[TYPO3-core] RFC: is_array check extension manager

Ernesto Baschny [cron IT] ernst at cron-it.de
Wed Aug 15 11:58:41 CEST 2007


Franz Holzinger wrote: on 15.08.2007 11:01:

sorry, did some further research after my previous post:

>>>>> if (isset($conf['constraints']['conflicts']) &&
>>>>> is_array($conf['constraints']['conflicts'])) {

>> Have you tested this without disabling PHP warnings?! The isset() works
>> even if the element to check isn't defined - returns false but no
>> warnings. As Michael mentioned before, please double check and test such
>> basic issues before posting to the Core-List. Thanks!
>> The isset($array['key']) && is_array($array['key']) is the correct way!
> 
> Here is the code to test it:
> $tmp = 'test';
> if (is_array($tmp))    {
>     echo $tmp['a']['1'];
> }
> This works fine under PHP 5.2.1. No isset($tmp) is necessary even if I
> have commented out the $tmp = 'test' line.

The problem is that in our case $tmp is already an array (not a string).
So your test will fail:

$tmp['b'] = 'test';
if (is_array($tmp['a']))    {
    echo $tmp['a']['1'];
}

Will print out a warning, because is_array will try to access the
"Undefined index:  a". So the isset() before is really required, which
is something I was never really sure about, but now I was able to track
down the exact problem.


Cheers,
Ernesto


More information about the TYPO3-team-core mailing list