Debugging By Dumping

By now, most of us will likely have used the dump($var); function made available for us in Symfony 2.6.

If you haven’t, or you think you can’t because you a) don’t have the latest and greatest version of Symfony, or b) don’t use Symfony, then never fear, you can include the VarDumper component in any project. No excuses.

Whilst the  dump($var); function is incredibly useful, in one instance so far, it has caused me more headaches than it has solved.

The Situation

I’m working on a new RESTful API using Symfony 2 as my back end.

Along the way, I want to restrict Users from being able to access other peoples data, for obvious reasons.

Without getting too deep into the code – as it’s really not that important to this problem / solution – I hit upon an issue where I wasn’t getting the expected output. Such is life of a developer.

However, I can tell you are getting twitchy from having not yet seen any code, so to placate your code cravings, here is the method:

    /**
     * @return array
     */
    public function findAll()
    {
        $accounts = $this->repository->findAll();

        foreach ($accounts as $account) {
            $this->denyAccessUnlessGranted('view', $account);
        }

        return $accounts;
    }

See, I told you, not much to look at.

At some point along the way (and in truth, I haven’t figured out exactly where as of yet), I know that $this->denyAccessUnlessGranted(‘view’, $account);  is having a bad time.

To begin with, I wanted to see exactly what the contents of $accounts was before it even hit the foreach loop.

To the dumper!

    /**
     * @return array
     */
    public function findAll()
    {
        $accounts = $this->repository->findAll();

        exit(dump($accounts));

        foreach ($accounts as $account) {
            $this->denyAccessUnlessGranted('view', $account);
        }

        return $accounts;
    }

Alas, no:

the-output-of-symfony-vardumper-dump

The next thing you might think is – ok, just use print_r($var); and be done with it.

Unfortunately, that’s not an option when dealing with most Doctrine entities. If you try, you may get lucky, you may hit funky maximum nesting level errors, or worse, you may crash your DHC client. Guess which I encountered?

My Solution

Never the less, there is a solution. Quite an old school solution. Something I used to use all the time before the VarDumper component was a thing:

exit(\Doctrine\Common\Util\Debug::dump($yourVariableHere));

This will give you an equivalent of print_r($var); but without the nasty blow ups:

the-output-of-doctrine-dump

It’s an old technique sir, but it checks out.

Now just to figure out why the test is failing, and everything will be right with the world once more.

The Yellow Peril

Back when I was a young whipper snapper, the first person in my life to own a ‘real PC’ was my granddad Roy.

Being an accountant, he needed to be able to work on his spreadsheets (I assume) from home, using a computer I could not begin to remember the make nor model of.

It had a green screen, so this was a while ago.

It also had that keyboard.

IBM Model M Mechanical Keyboard

I distinctly remember the sound the IBM Model M keyboard made. Such solid build quality.

I wondered for about ten years why his keyboard had sounded and felt so different to the keyboards I used at home, school, and at work.

Then a few years ago, I heard about Mechanical Keyboards through a forum, and began doing a little research.

It turns out that these things aren’t cheap. Your modern day equivalent is about £100 or more. That’s a fair old chunk of change for a keyboard.

But, I figured, I use my keyboard every day. I do a lot of typing – whether it’s video write ups, blog posts, and / or coding – my keyboard(s) get hammered.

filco-majestouch-2

Anyway, I treated myself to one. Sorry for the terrible crop. And yes, it is a bit dirty (did I mention I hammer my keyboards?).

What a fantastic keyboard this is.

Recently I have been umm-ing and ahh-ing over whether to ditch my home PC in favour of an iMac.

It turns out ol’ Steve and his crew didn’t get so rich by throwing in a keyboard and mouse Apple iTrackpad2 Pro for free. No sir. If you want an £1800 Apple computer then being able to actually use it is going to cost you £100+ more.

I’ve used the Apple keyboard. I’m not a huge fan. It’s all right but it’s not in the same league as my Filco Majestouch 2. I heard they released a new keyboard also, which I managed to try recently and couldn’t see how it was any different to the old one.

As it turns out Filco actually do a Mechanical keyboard for the Mac. Good stuff.

But what caught my eye even more was this beast:

filco-majestouch-2-yellow-key-cap-version

That’s something else, isn’t it?

What immediately sprang to mind:

only-fools-and-horses-the-yellow-peril

only-fools-and-horses-yellow-peril-paint-sceneI’m swaying away from buying an iMac currently. Dual booting Ubuntu (work) and Windows 10 (gaming and music production) seems to be a good way forward.

I record all the content for this site on a Macbook Pro, so that’s not affected by this change.

And it means I don’t need to shell out another £100+ on another mechanical keyboard.

Whilst the yellow keyboard is a little on the crazy side for me, I do think this looks really cool:

filco-blue-keycaps

Only £4.99 as well. Quite the saving.

Does anyone out there own the Filco Delboy? Pictures please!