|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31186 Inconsistent datatype for offset when using ArrayAccess
Submitted: 2004-12-19 17:33 UTC Modified: 2005-02-09 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: Jason at AMP-design dot net Assigned:
Status: No Feedback Package: SPL related
PHP Version: 5.0.3 OS: Windows 2003 / CentOS 3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: Jason at AMP-design dot net
New email:
PHP Version: OS:


 [2004-12-19 17:33 UTC] Jason at AMP-design dot net
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);
		return $this->array[$index];

	public function offsetSet($index, $value) {
		if ($index === NULL) {
			echo 'Set on NULL'."\r\n";
			$this->array[] = $value;
		$this->array[$index] = $value;

	public function offsetUnset($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++;


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
<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 />


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-10 23:20 UTC]
Please try using this CVS snapshot:
For Windows:

Please, try CVS snapshot, I can't reproduce it under Linux.
 [2005-01-11 13:21 UTC] Jason at amp-design dot net
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.
 [2005-01-31 22:30 UTC]
Do NOT add comments to your OWN report!!!!!!!!!!!!!!!!!!!
Correct address is:

 [2005-02-09 01:00 UTC] php-bugs at lists dot php dot net
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".
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 18 01:05:45 2022 UTC