[Typo3-dev] PHP5
Christian Jul Jensen
christian at jul.net
Tue Apr 20 18:43:43 CEST 2004
Hi devs
I've been spending some time during the last week moving to PHP5. I
took me some time to get it compiled on my machine, but I finally got
it to work. And then I've been doing a little testing with TYPO3.
Just thought that I would share my experiences with you guys and maybe
save you some time.
In general I've been running in to two kinds of problems, they both
have to do with the use of arrays.
First thing:
the PHP native function array_merge, now issues an E_WARNING if any of
the parameters are not an array.
---example:
if($I_had_brains) {
$a = array('I', 'would', 'do', 'my', 'work', 'instead', 'of');
}
$b = array('playing', 'around', 'with', 'PHP5');
$result = array_merge($a,$b);
---
Assuming $I_had_brains=false, would work with PHP4 but fail in PHP5.
This behavior is actually used some places in the TYPO3 core. I
managed to fix the ones I've found (with some supervising from
Kasper). I will check up on those and commit them to cvs one of the
days.
The other thing:
PHP5 issues an E_ERROR on illegal use of string offsets, that is:
---example
$a = 'I honestly thought this was an array';
echo $a[3];
echo $a[3]['someindex'];
---
in PHP4 this will return an h (the third letter in the string), and
ignore the line third line.
PHP5 returns an h, and a fatal error.
Althoguh this makes pretty much sense, it is a problem because you
might also get a fatal error in the following case, even tough you
actually check for the existence of the array that you need.
---example
$my_array = $some_weird_function_that_returns_a_multidim_array();
if(is_array($my_array['some']['special']['value']['that']['i']['need']))
{
apply_logic();
}
---
in PHP5, in order not to risk a fatal error, this would have to be:
---example
$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();
}
---
I found the use of this several places in templavoila. And my guess is
that it will be found lots of places in both the core and other
extensions, including my own.
There's probably better ways to solve this problem, one could be to
have a function in t3lib_div to handle it.
I planned to develop my next project in PHP5, but right now I'm not
sure because it seems like there's a lot of small things to be
handled, and that simply takes to much time for me right now. Anyway,
I will probably try to spend some time identifying problems in the
core. so the next release will be PHP compatible at least in the core.
--
./mvh Christian Jul Jensen
"Hvis du vil skrive til Hotline, opgiv venligst hvilket
windows-styresystem du anvender (windows 95 eller nyere,
MAC OS X, LINUX)" -- Nørresundby Bank Netbank
More information about the TYPO3-dev
mailing list