#38109 [Opn->Bgs]: visibility of property is processed incorrectly
| From: | helly@php.net | Date: | Sat, 15 Jul 2006 09:42:39 +0000 |
| Subject: | #38109 [Opn->Bgs]: visibility of property is processed incorrectly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-99462@lists.php.net to get a copy of this message | ||
ID: 38109
Updated by: helly@php.net
Reported By: public at grik dot net
-Status: Open
+Status: Bogus
Bug Type: SPL related
-Operating System: Linux, Windows
+Operating System: *
-PHP Version: 5.1.4
+PHP Version: *
-Assigned To:
+Assigned To: helly
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
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.
Previous Comments:
------------------------------------------------------------------------
[2006-07-15 02:50:13] public at grik dot net
Description:
------------
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:
---------------
A)
class Rules extends ArrayObject {
public $len;
function __construct($array){
parent::__construct($array,2);
$this['len'] = 2;
}
}
$x = new Rules(array(1,2));
var_dump($x->len);
B)
class Rules extends ArrayObject {
protected $len;
function __construct($array){
parent::__construct($array,2);
$this['len'] = 2;
}
}
$x = new Rules(array(1,2));
var_dump($x->len);
Expected result:
----------------
A) int(2)
B) Fatal error</b>: Cannot access protected property Rules::$len
Actual result:
--------------
A) NULL
B) int(2)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38109&edit=1