ID:               31186
 Updated by:       [EMAIL PROTECTED]
 Reported By:      Jason at AMP-design dot net
 Status:           Feedback
 Bug Type:         SPL related
 Operating System: Windows 2003 / CentOS 3
 PHP Version:      5.0.3
 New Comment:

Do NOT add comments to your OWN report!!!!!!!!!!!!!!!!!!!
Correct address is:

  http://bugs.php.net/bug.php?id=31186&edit=2



Previous Comments:
------------------------------------------------------------------------

[2005-01-12 00:51:43] 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-11 13:21:13] 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-10 23:20:08] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Please, try CVS snapshot, I can't reproduce it under Linux.

------------------------------------------------------------------------

[2004-12-19 17:33:28] Jason at AMP-design dot net

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 this bug report at http://bugs.php.net/?id=31186&edit=1

Reply via email to