Hi,
this is a plain design fault on your side:
<?php
$a = 'this is not an array';
if( is_array( $a['foo'] ) )
print '1';
[...]
?>
allright, just set $a to be a string, thats allright, now
you check wether an string-offset ( foo ) is an array or
not which causes an FATAL ERROR on PHP5.
Now if you wrote some clean code you would have done:
<?php
$a = 'this is not an array';
if ( is_array ( $a ) ) {
if ( is_array ( $a['foo'] ) ) {
print '1' ;
}
} else {
print 'nope';
}
?>
Now this makes sense as you first of all would make sure if $a is an
array and not start with the first index ( which doesn't exist as $a
is not even an array )
-- red
PS: PHP5 says:
Fatal error: Cannot use string offset as an array in /www/htdocs
test_offset.php on line 6
[...]
> 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
[...]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php