Archive for September, 2009

Type Hinting in PHP

Saturday, September 5th, 2009

PHP 5 introduces Type Hinting. But it does so in the usual PHP way: It’s neither fish nor fowl. You’ll be exited at first when you discover the new feature. And then you’ll be disappointed. Because things do not work like you’d expect. Suppose you do something like this:

  1. <?php
  2.  
  3. function foo ( string $bar) {
  4. echo $bar;
  5. }
  6. foo ('Hello World!');
  7.  
  8. ?>

What happens, when you execute the above code? You will get a rather cryptic error message:

  1. Catchable fatal error: Argument 1 passed to foo() must be an instance of string, string given.

So the method expected a string as the first parameter and you passed a string to it, but PHP chose to throw up regardless. Great, isn’t it? Of course, the reason for this is right at the very bottom of the PHP documentation on Type Hinting. All the way down the page below a number of examples:

Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn’t supported.

Doh!

Amazing Australian broadcasters

Tuesday, September 1st, 2009

Totally unrelated to anything, but it just came to my mind: Australian radio service is great. They’ve got great radio shows all through the night on a weekday presented by hosts with very strange Australian accents. I can get the whole Australian radio experience on a any European evening. In my bathroom. Or anywhere else. Australian radio: Amazing! The internet: Amazing! Australian radio and the internet combined: You guess what!

PS: I know that it’s early morning in Sydney right now. Never mind.

Printer-less printing

Tuesday, September 1st, 2009

Sometime in February I got rid of my ink-jet printer. Ever since I’ve spent a total of 3,15 EUR on printing the occasional file, form or letter at a nearby copy-shop. Way cheaper than the ink cartridges I had to buy regularly (while I didn’t print that much, the printer used a lot of ink during self-cleaning operations). And a lot friendlier to the environment. Yay!