Does passing an uninitialized array variable initialize it? (PHP 5)



The following code never sees the end of the array, and generates an
out of memory error under PHP5 (both CLI and Apache module) :

while (isset($rank[$i])) {
$rank[$i] = trim($rank[$i++]);
}

Moving the post increment to a separate line fixes this issue:

while (isset($rank[$i])) {
$rank[$i] = trim($rank[$i]);
$i++;
}

For some reason PHP5 appears to be initializing $rank[($i+1)] each
time, perhaps because it's passing the value to trim(). The subsequent
isset() test on that element succeeds so the loop continues
indefinitely as each new element is initialized.

It works as expected under PHP4, stopping once it hits the end of the
array. I can't find any documentation which hints at any change to the
handling of uninitialized variables which caused this code to break.

Thanks in advance for any help...

.



Relevant Pages

  • Re: Does passing an uninitialized array variable initialize it? (PHP 5)
    ... For some reason PHP5 appears to be initializing $rankeach ... issettest on that element succeeds so the loop continues ... I did a quick look and don't see where this was behavior was explicitly changed, but it looks more like a bug to me. ...
    (comp.lang.php)
  • Re: Does passing an uninitialized array variable initialize it? (PHP 5)
    ... For some reason PHP5 appears to be initializing $rankeach ... issettest on that element succeeds so the loop continues ... handling of uninitialized variables which caused this code to break. ...
    (comp.lang.php)
  • Re: passing a struct with an array by reference
    ... public void getData(out micDataReturn rem) ... // Allocate the array. ... if you are just initializing the structure with 0 for the ... micDataReturn res = new micDataReturn; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Array pulldowns for text fields
    ... >> You are initializing the array in Form.Init, ... combobox has initialized, so the combobox will not see the array ... I've done a lot of reading over the last few weeks in an attempt to learn and understand these sequences and the general design concepts. ...
    (microsoft.public.fox.programmer.exchange)
  • Wierd Sun T3 behaviour
    ... We have recently aquired a used Storedge T3 Array. ... Copyright 1997-1999 Sun Microsystems, ... Loop A Configured as ... Initializing System Drivers... ...
    (comp.sys.sun.hardware)