|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-01-10 23:20 UTC] tony2001@php.net
[2005-01-11 13:21 UTC] Jason at amp-design dot net
[2005-01-12 00:51 UTC] jason at amp-design dot net
[2005-01-31 22:30 UTC] sniper@php.net
[2005-02-09 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
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 />