php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28129 Overloading [] -operators would be very userful
Submitted: 2004-04-23 19:27 UTC Modified: 2004-04-25 13:17 UTC
From: niz at sci dot fi Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.0RC1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-04-23 19:27 UTC] niz at sci dot fi
Description:
------------
I was developing own array class for php5 and result was not very usable because I can't overload [] -operator..
It's good that iteration is now in php5 but better overloading support is needed.

It could work something like this:

class xArray {
    private $data = array(0 => "first", 1 => "second");
    function __index($key) {
        return $this->data[$key]
    }
}

$test = new xArray();
print($test[0]); // would print "first"



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-23 22:58 UTC] derick@php.net
We're not going to overload any more operators, you can use SPL for this anyway.
 [2004-04-25 13:17 UTC] helly@php.net
Also have a look at interface ArrayAccess
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 26 14:01:32 2024 UTC