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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: niz at sci dot fi
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Thu Dec 26 10:01:29 2024 UTC