[Typo3-dev] PHP5
Christian Jul Jensen
christian at jul.net
Tue Apr 20 22:18:39 CEST 2004
Kasper Skårhøj <kasper at typo3.com> writes:
> 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.
Actually I think it fits pretty good in the type-loose scheme of PHP
to allow it. I mean, if you merge an array with nothing, it makes
sense to end up with the array. But it's good coding style, and avoids
some potential bugs, I think
> @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?
I've been looking in to that, but I can't see that there is. What is
possible is to regsiter your own error_handler, and let that filter
out the messages you don't want. But I don't think that solves the
problem, because it's still a fatal error, the Zend engine simply
don't know hoe to proceed. Getting rid of the errormsg doesn't really
help you there.
I haven't tested this though, it might work.
"Martin T. Kutschker" <Martin.T.Kutschker at blackbox.net> writes:
> Note that it should reade $a{4} anyway (square brackets for string
> indexing is deprecated).
I know, but it's still supported in PHP5, even though it has been
deprecated in all of PHP4 as far as I know.
As Kasper said I couldn't imagine anybody using that feature anyways,
it was just to show a simple example of what goes wrong.
> What happens when you do this?
>
> $my_array = $some_weird_function_that_returns_a_multidim_array();
> if(isset($my_array['some']['special']['value']['that']['i']['need']))
> {
> apply_logic();
> }
That actually works, the only thing is, you still don't know if it's
an array, but using that you could check it in only two calls:
if(isset($my_array['some']['special']['value']['that']['i']['need']))
&&
is_array($my_array['some']['special']['value']['that']['i']['need']))
instead of the horrible thing I posted earlier.
Still I think that it's a really weird behaviour, I think it must be a
side-effect of something else. Ie. it doesn't issue a fatal error if
you execute.
echo
is_array($my_array['some']['special']['value']['that']['i']['need']);
Doesn't seem very well-designed to me.
--
Julle
More information about the TYPO3-dev
mailing list