[Typo3-dev] PHP5

Kasper Skårhøj kasper at typo3.com
Tue Apr 20 19:57:05 CEST 2004


About array_merge(): 

I told Christian that I do consider it a bug in TYPO3 if a non-array is
given to array_merge(). In fact I thought that it would also make errors
in PHP4 which is why I was surprise that hte issue came up. But
apparently there are a few places. Easy fix.


> > in PHP5, in order not to risk a fatal error, this would have to be:
> > $my_array = $some_weird_function_that_returns_a_multidim_array();
> > if(     is_array($my_array['some']) && 
> >         is_array($my_array['some']['special']) && 
> >         is_array($my_array['some']['special']['value']) &&
> >         is_array($my_array['some']['special']['value']['that']) &&
> >         is_array($my_array['some']['special']['value']['that']['i']) &&
> >         is_array($my_array['some']['special']['value']['that']['i']['need'])
> > ) {
> >         apply_logic();
> > }
> 
> That would be really cruel. I hope there is simple solution for that because I also 
> relied on the old syntax at many places ...

Yes. This is horrific.

Sometimes you will see me check some things like this. For instance 

if (is_array($TCA['sometable']['columns']['somefieldname]) &&
$TCA['sometable']['columns']['somefieldname]['config']['somekey'])	{
	....
}

The reason for this is that at some point in time I experienced that
*checking* directly for
$TCA['sometable']['columns']['somefieldname]['config']['somekey'] would
actually make $TCA['sometable']['columns']['somefieldname].... an array
(which I wouldn't like it to be).

I suppose that the same problem would arise as well if we set error
handling to E_ALL - if you try this you will see hundreds of errors
about non-initialized variables. That was the moment when I decided not
to waste my time and thousands of codelines on initializing variables
(and checking for set array keys!).

@christian: Just like error levels can be set to E_ALL ^E_NOTICE etc.
don't you think PHP5 might have a way to disable the error for accessing
a non-existing key in an array?



> But if there is no easy, at least we have something to complain about on the PHPconference ;-)

Yes, lets do that. I'll bring some wire-cramps and rubberbands.

- Kasper "Sniper" Skaarhoj






More information about the TYPO3-dev mailing list