|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38109 visibility of property is processed incorrectly
Submitted: 2006-07-15 02:50 UTC Modified: 2006-07-15 10:20 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: public at grik dot net Assigned: helly (profile)
Status: Not a bug Package: SPL related
PHP Version: * 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.
Block user comment
Status: Assign to:
Bug Type:
From: public at grik dot net
New email:
PHP Version: OS:


 [2006-07-15 02:50 UTC] public at grik dot net
When I declare a property as "public", it's being ignored.
When I declare it as protected or private it is processed and visible from outside of the object.

Reproduce code:
class Rules extends ArrayObject {
    public $len;
    function __construct($array){
        $this['len'] = 2;
$x = new Rules(array(1,2));

class Rules extends ArrayObject {
    protected $len;
    function __construct($array){
        $this['len'] = 2;
$x = new Rules(array(1,2));

Expected result:
A) int(2)

B) Fatal error</b>:  Cannot access protected property Rules::$len

Actual result:

B) int(2)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-15 09:42 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The ",2" in the constructor call means ArrayObject::SPL_ARRAY_ARRAY_AS_PROPS which means use the array as properties if there is no conflict with visible properties. That is in case A) the property len is visible outside hence the property can be used. In case B) the property len is not used so that the array is being used instead. You will see an interesting behavior if you provide a class method in case B that dumps the contents.
 [2006-07-15 10:20 UTC] public at grik dot net
Thanks, then it's a documentation bug.

In the documentation there is no mention that it is about _not_visible_ properties only.
"Array indices can be accessed as properties in read/write."
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Wed Oct 24 00:01:26 2018 UTC