php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29897 $array[] syntax does not work with ArrayAccess implementation.
Submitted: 2004-08-30 16:10 UTC Modified: 2004-08-30 20:38 UTC
From: sb at sebastian-bergmann dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.* OS: *
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sb at sebastian-bergmann dot de
New email:
PHP Version: OS:

 

 [2004-08-30 16:10 UTC] sb at sebastian-bergmann dot de
Description:
------------
$array[] syntax does not work with ArrayAccess implementation.

Reproduce code:
---------------
<?php
class TestArray implements ArrayAccess {
    private $array = array();

    public function offsetExists($offset) {
        return isset($this->array[$offset]);
    }

    public function offsetGet($offset) {
        return $this->array[$offset];
    }

    public function offsetSet($offset, $value) {
        $this->array[$offset] = $value;
    }

    public function offsetUnset($offset) {
        unset($this->array[$offset]);
    }
}

$test = new TestArray;

// Does not work.
$test[] = 'Hello'; $test[] = ' World!';

// Works.
// $test[0] = 'Hello'; $test[1] = ' World!';

print $test[0] . $test[1];
?>

Expected result:
----------------
Hello World!

Actual result:
--------------
Notice: Undefined offset:  0 in D:\test2.php on line 10
Notice: Undefined offset:  1 in D:\test2.php on line 10

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-30 20:38 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Your code is wrong, look @ array_access_007.phpt
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC