You learn something every day

Posted in: Uncategorized

I’ve been working with PHP for a very long time. Working with a language for over a decade, you come to the point where (for better or worse) you know every quirk, nuance and feature of the language. Or at least that’s what I thought, because today I learnt something new, and very, very useful.

There’s often the case where, especially in heavy OOP projects, you want to extend a class just to modify the way a single method works. This is called overloading, and combined with dependency injection it allows you to modify core classes of a library, without the evil sin of hacking the core code. However, often these methods will call a parent method, using parent::whatever(). If you want to override that method but still call its parent, you can’t use the same parent keyword because the class you’re overriding is now the new parent. You need to call the grandparent, but there’s no grandparent keyword! What a pickle.

Well it turns out if you call a non-static method that is an ancestor of the current class, PHP is clever enough to call it dynamically and keep the $this context. So you can effectively just call the grandparent’s method directly and statically. This false bug report explains it better.

100-year-old Norwegian mystery is unravelled

Posted in: Interesting

100-year-old Norwegian mystery is unravelled

When the mayor of a Norwegian town wrapped up a brown paper package in 1912, he began a 100-year mystery.

The package survived two world wars and twice narrowly avoided being thrown away

Johann Nygaard handed over the parcel to the local authorities in Sel in the 1920s with no word of explanation. It bore the message: “Can be opened in 2012.”

Whilst it may have been an anti-climax, I’m astounded by the fact it actually survived that long. Especially with such high expectations of what’s inside. I almost wish they didn’t open it, seeing as it sparked so much creativity and wonder.

Reminds me of when I was younger and I read about a site called FutureMe from a news site (possibly Digg?). I put it a message to the future me for my 21st birthday and completely forgot about it. Needless to say when I received the email about 3 years later I was pleasantly surprised that a younger me could muster up sarcastic wit contained in the email.

Update: I went ahead and fished out the original email, it was composed on September 20, 2006 for March 22nd 2010. And it looks like future me is still going strong.

Magento – admin login redirects to same page (cookies not working)

Just a quick one. If you’re having problems logging in to the Magento admin (e.g. it redirects you back to the login page with no error) or you can’t add items to your basket, you’re most probably have a cookie problem.

To fix, in the core_config_data table find the row with the path ‘web/cookie/cookie_domain‘. This should be set to your domain, or NULL for PHP to automatically determine the domain. A client was recently having a problem where this had been manually set to an empty string, which was causing cookie issues, and the aforementioned seemed to fix it. Be sure to clear your cache afterwards.