From: Jason at AMP-design dot net
Operating system: Windows 2003 / CentOS 3
PHP version: 5.0.3
PHP Bug Type: Zend Engine 2 problem
Bug description: Inconsistent datatype for offset when using ArrayAccess
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 />
--
Edit bug report at http://bugs.php.net/?id=31186&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31186&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31186&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31186&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31186&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31186&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31186&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31186&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31186&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31186&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31186&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31186&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31186&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31186&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31186&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31186&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31186&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31186&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31186&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31186&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31186&r=mysqlcfg