How to do type/existence checking in PHP5
| From: | Christian Jul Jensen | Date: | Fri, 23 Apr 2004 09:55:53 +0000 |
| Subject: | How to do type/existence checking in PHP5 | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-184371@lists.php.net to get a copy of this message | ||
Hi
In PHP5 the behaviour of illegal string offsets has changed. This is
documented in the 'thin changes' file.
This gives a problem in checking for existence / types of values,
directly into a deeper level of a multidimensional array.
I reported this as a bug[1] because I find the behaviour unfortunate, and
furthermore it's inconsistent. This was refused, with a note 'So don't
do it'. I think it's a really bad idea not to check the
existence/types of values, before using them, so how should this be done
properly in PHP5, without risking fatal errors in the case of a
non-existent array?
This is a problem in migrating applications from PHP4 because the
error will not appear unless the value deosn't exist, which is exactly
why you do the check.
[1] http://bugs.php.net/bug.php?id=28107
--
./mvh Christian Jul Jensen
Frelance webprogrammer
TYPO3 Typehead Denmark