Blog of me. I’m Alexander Jones.

01 March 2010

PHP wart of the day

Just spent about a half hour debugging this. It's such a shame that if you try to do anything neat in PHP, stupid behaviour foils your plan:

php > $n = NULL;
php > var_dump($n['something']);
NULL
php > var_dump($n[0]);
NULL

How this makes any sense is beyond me. It even happens if $n is FALSE...

Python, for comparison, throws an exception sanely:

In [1]: n = None
In [2]: n['something']
TypeError: 'NoneType' object is unsubscriptable

No comments: