Doc #63217 [Com]: Behavior of implementing the ArrayAccess interface has been changed in php 5.4

From: Date: Sun, 07 Apr 2013 17:44:34 +0000
Subject: Doc #63217 [Com]: Behavior of implementing the ArrayAccess interface has been changed in php 5.4
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9729@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63217&edit=1

 ID:                 63217
 Comment by:         david at grudl dot com
 Reported by:        kmsheng at pixnet dot tw
 Summary:            Behavior of implementing the ArrayAccess interface
                     has been changed in php 5.4
 Status:             Open
 Type:               Documentation Problem
 Package:            Arrays related
 Operating System:   freebsd
 PHP Version:        5.4Git-2012-10-04 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

This is really buggy.

$test['0']; // prints int(0)

but

$key = '0'; 
$test[$key]; // prints string(1) "0"


Previous Comments:
------------------------------------------------------------------------
[2012-10-05 04:54:32] laruence@php.net

numeric string key will cast to number, I think this is a improvement, to be 
consistent with the internal dim fetch.

but yeah, we need a document of such change, change to doc problem.

------------------------------------------------------------------------
[2012-10-04 10:14:49] kmsheng at pixnet dot tw

Description:
------------
Execute the test script provided below in php 5.3.10 and php 5.4.0-3 may get different results which
are string(1) "0" and int(0).

I don't know if this is a bug or a patch.

Test script:
---------------
<?php
class Test implements ArrayAccess {

    public function offsetExists($off)
    {
    }

    public function offsetUnset($off)
    {
    }

    public function offsetSet($off, $el)
    {
    }

    public function offsetGet($off)
    {
        var_dump($off);
    }
}

$test = new Test();

$test['0'];

Expected result:
----------------
string(1) "0"

Actual result:
--------------
int(0)


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



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63217&edit=1


Thread (4 messages)

« previous php.doc.bugs (#9729) next »