php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #37882 overloading array access
Submitted: 2006-06-22 07:39 UTC Modified: 2010-12-22 12:56 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: php at bouchery dot com Assigned: johannes (profile)
Status: Closed Package: *General Issues
PHP Version: 5.1.5CVS OS: all
Private report: No CVE-ID: None
 [2006-06-22 07:39 UTC] php at bouchery dot com
Description:
------------
I would like to overload array access like this

<?php
class MyClass {
  private $parameters = array();

  function __set( $name, $value, $key ) {
    if( ! isset( $this->parameters[ $name ] ) ) {
      $this->parameters[ $name ] = array();
    }
    $this->parameters[ $name ][ $key ] = $value;
  }
}

$object = new MyClass;
$object->a[ 'x' ] = 'value';
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-09 07:56 UTC] ois at oisnot dot com
AS has been specified in comments here:
http://no2.php.net/manual/en/language.oop5.overloading.php

I think this should be set with the __set overload not __get though.
 [2010-12-22 12:56 UTC] johannes@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: johannes
 [2010-12-22 12:56 UTC] johannes@php.net
The ArrayAccess interface exists meanwhile for this purpose.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 18:01:31 2025 UTC