2007.05.01

PHP Idiosyncrasies

Three reasons to make sure you know your programming language:


<?php

function test($code) {
$result = @eval("return ({$code});");
print ($result ? 'true ' : 'false ') . "$coden";
}

test( "gettype(key(array('s' => ''))) == 'string'" );
test( "gettype(key(array('1' => ''))) == 'string'" );

test( "'s' == 0" );
test( "0 == 's'" );

test( "$x == $x++" );
test( "(int)$x == $x++" );

And here's the output:


true gettype(key(array('s' => ''))) == 'string'
false gettype(key(array('1' => ''))) == 'string'
true 's' == 0
true 0 == 's'
false $x == $x++
true (int)$x == $x++

In case you didn't catch what PHP is doing on the last pair, here's the equivalent processing in PHP code:


$y = &$x;
$x++;
($x == $y)

When casting $x with (int), PHP is no longer able to make use of the "let's just use a reference" over-optimization. Personally, I think it's a bug that the behaviour differs between the two.


Debuggers beware! ;)

18:50 Posted in General | Permalink | Comments (0) | Email this

2006.03.29

Blogs... the latest Internet virus

With only one (real) entry of my own and a few words via text chat, I've managed to convince my best mate to start a blog of his own. For those that aren't technically minded, while I do/will try to cater for you too, I'm sure you'll find a lot of more mind tingling thoughts over his way. Check it out at http://seanwilliams.blogspirit.com/.

00:40 Posted in General | Permalink | Comments (0) | Email this

2006.03.25

A new trend begins?

I've finally started a blog. This service does everything I want - categories, template editing, unicode...

ブログをやっと始めたよ〜。このブログスピリットはカテゴリー、テンプレート更新、ユニコードなどわたしがしたいことが全て出来ます。

10:20 Posted in General | Permalink | Comments (2) | Email this