[TYPO3-core] RFC: is_array check extension manager

Franz Holzinger franz at fholzinger.com
Wed Aug 15 11:01:22 CEST 2007

Hello Oliver, 

> Franz Holzinger schrieb:
>> Michael Stucki writes:
>>> No because he loops over $conf['constraints']['conflicts'].
>>> $conf['constrains'] can be an array while still there might be no
>>> $conf['constraints']['conflicts']! So checking this first using isset
>>> is the only right thing to do.
>>> Please double-check such tiny issues before writing to this list.
>> I see no sense in this to check isset anded with is_array. If it is an
>> array it must be also be set. So the first parameter is redundant.
>> See php.net
>> bool is_array ( mixed $var )
>> Finds whether the given variable is an array.
>>>> 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.
// $tmp = 'test'; 

In the Install Tool:
[SYS][displayErrors] = 1 

This also works: 

$tmp = 'test'; 

if (is_array($tmp['a']))	{
	foreach ($tmp['a'] as $k => $v)	{
		echo $tmp['a']['1']['2'];

double test:
$tmp = 24; 

It also works with integers. 

debug info:
Integer  $tmp  24 

And yes, the error message is shown in this case but only for the not array 
used in the foreach loop: 

echo $hello['1']['2']['3'];
foreach ($hello as $k => $v)	{
	echo $v['3'];

Warning: Invalid argument supplied for foreach() in 
tx_ttproducts_main.php on line 121 

So it seems to be an overkill even for PHP5.
Or is there any test environment where I can see that the leading isset is 
really needed under specific circumstances? 

 - Franz 



More information about the TYPO3-team-core mailing list