Description:
------------
On Windows 2003 / PHP 5.0.3 / Apache 2.0.52 I get an invalid data type for the $index parameter for offsetGet (and probably for other offset* methods).
As you can see from the result I get, the vardump returns $index as having 'UNKNOWN' as the datatype.
It does appear that running this in PHP 5.0.2 / CentOS 3 (RHEL3) / Apache 2.0.48 seems to work OK and give the expected result. I don't know if this is because of a difference caused by the PHP version or the OS it's self.
Changing $index == NULL seems to shut PHP up about this werid error, however this is besides the point, as PHP shouldn't be creating variables of an 'UNKNOWN' type, and should be producing consistent results across platforms for this sort of stuff.
Reproduce code:
---------------
header('Content-type: text/plain');
class FooBar implements ArrayAccess {
private $array = array();
public function offsetExists($index) {
return isset($this->array[$index]);
}
public function offsetGet($index) {
/* index is NULL because we are assigning into NULL */
if ($index === NULL) {
echo 'Get on NULL'."\r\n";
$this->array[] = new self();
return end($this->array);
}
var_dump($index);
return $this->array[$index];
}
public function offsetSet($index, $value) {
if ($index === NULL) {
echo 'Set on NULL'."\r\n";
$this->array[] = $value;
return;
}
$this->array[$index] = $value;
}
public function offsetUnset($index) {
unset($this->array[$index]);
}
}
$i = 0;
$foo = new FooBar();
$foo[] = $i++;
$foo[] = $i++;
$foo[] = $i++;
/* calls GET on $foo[] before calling set on $foo[]['test']
* as it needs to have some contents in $foo[] for ['test'] to
* be set into
*/
$foo[]['test'] = $i++;
print_R($foo);
Expected result:
----------------
Set on NULL
Set on NULL
Set on NULL
Get on NULL
FooBar Object
(
[array:private] => Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => FooBar Object
(
[array:private] => Array
(
[test] => 3
)
)
)
)
Actual result:
--------------
Set on NULL
Set on NULL
Set on NULL
UNKNOWN:0
<br />
<b>Warning</b>: Illegal offset type in <b>D:\Documents\Web Development\spl_test.php</b> on line <b>18</b><br />
<br />
<b>Fatal error</b>: Objects used as arrays in post/pre increment/decrement must return values by reference in <b>D:\Documents\Web Development\spl_test.php</b> on line <b>41</b><br />

Sorry, I listed it as CentOS in the description by accident because it was similar to another SPL bug I reported that did affect CentOS. It only affects windows, and I will check with a current CVS version tonight if I get time and get back to you. (I think I stated in the original text that it doesn't affect CentOS / Linux in general)

[2005-01-12 00:51 UTC] jason at amp-design dot net

I've tested this with the latest CVS version and I can confirm I have the same result.

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".