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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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 23:01:28 2024 UTC