From: oliver dot graetz at gmx dot de
Operating system: WinXP, Debian Linux
PHP version: 5.1.0RC1
PHP Bug Type: SPL related
Bug description: Contradictory errors using ArrayAccess
Description:
------------
I wrote a class implementing ArrayAccess that should behave like a normal
array to the outside world. So If I used an element in this array it
should be usable like any other array. But there was a problem if the
"array" elements were arrays themselves. I got this error:
Fatal error: Objects used as arrays in post/pre increment/decrement must
return values by reference in t.php on line 123
OK, you want a reference, you get it. I changed offsetGet to &offsetGet.
This worked fine with PHP5.0. But in PHP5.1 the parser became more picky
about this:
Fatal error: Declaration of WAF_Config::offsetGet() must be compatible
with that of ArrayAccess::offsetGet() in myclass.php on line 234
This is correct but it makes implementing ArrayAccess in a way consistent
with ordinary arrays impossible!
Reproduce code:
---------------
<?php
class test implements ArrayAccess
{
private $data=array();
function offsetSet($key,$value) { $this->data[$key] = $value; }
// function &offsetGet($key) { return $this->data[$key]; }
function offsetGet($key) { return $this->data[$key]; }
function offsetUnset($key)
{
if (array_key_exists($key,$this->data)) {
unset($this->data[$key]); }
}
function offsetExists($key) { return array_key_exists($key,$this->data);
}
}
$t=new test();
$t['huba']=array('one','two');
$t['huba'][]='three';
print_r($t['huba']);
Expected result:
----------------
Array ( [0] => one [1] => two [2] => three )
Actual result:
--------------
using offsetGet
Fatal error: Objects used as arrays in post/pre increment/decrement must
return values by reference in t.php on line 17
using &offsetGet
Fatal error: Declaration of test::offsetGet() must be compatible with that
of ArrayAccess::offsetGet() in t.php on line 2
--
Edit bug report at http://bugs.php.net/?id=34783&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34783&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=34783&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=34783&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34783&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34783&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34783&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34783&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34783&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34783&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34783&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=34783&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=34783&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34783&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34783&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34783&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34783&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34783&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34783&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34783&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34783&r=mysqlcfg