Bug #55131 [Opn->Bgs]: HUITA fix this bug
| From: | scottmac@php.net | Date: | Wed, 06 Jul 2011 06:26:44 +0000 |
| Subject: | Bug #55131 [Opn->Bgs]: HUITA fix this bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161632@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55131&edit=1
ID: 55131
Updated by: scottmac@php.net
Reported by: archon dot saratov at gmail dot com
Summary: HUITA fix this bug
-Status: Open
+Status: Bogus
Type: Bug
Package: *Programming Data Structures
Operating System: Windows, FreeBSD
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
things returned by __get() are read only.
When you have
$c1->e1[] = 1;
It's really calling __get on e1 and then appending to the array the value 1. The
latter can't happen since it's read only.
Previous Comments:
------------------------------------------------------------------------
[2011-07-04 14:47:06] archon dot saratov at gmail dot com
Description:
------------
bad working a __get method
Test script:
---------------
<?php
class C1 {
protected $arr = array( 'e1' => array() );
public function __get($propertyName) {
if(isset($this->arr[$propertyName])) return $this->arr[$propertyName];
}
public function __set($propertyName, $value) {
if(isset($this->arr[$propertyName])) $this->arr[$propertyName] = $value;
}
}
$c1 = new C1();
var_dump($c1->e1);
$c1->e1[] = 1;
var_dump($c1->e1);
Expected result:
----------------
array
empty
array
0 => int 1
Actual result:
--------------
array
empty
( ! ) Notice: Indirect modification of overloaded property C1::$e1 has no effect
in E:\Server\xampp\htdocs\test.php on line 18
array
empty
------------------------------------------------------------------------
[2011-07-04 14:46:22] archon dot saratov at gmail dot com
Description:
------------
bad working a __get method
Test script:
---------------
<?php
class C1 {
protected $arr = array( 'e1' => array() );
public function __get($propertyName) {
if(isset($this->arr[$propertyName])) return $this->arr[$propertyName];
}
public function __set($propertyName, $value) {
if(isset($this->arr[$propertyName])) $this->arr[$propertyName] = $value;
}
}
$c1 = new C1();
var_dump($c1->e1);
$c1->e1[] = 1;
var_dump($c1->e1);
Expected result:
----------------
array
empty
array
0 => int 1
Actual result:
--------------
array
empty
( ! ) Notice: Indirect modification of overloaded property C1::$e1 has no effect
in E:\Server\xampp\htdocs\test.php on line 18
array
empty
------------------------------------------------------------------------
[2011-07-04 14:44:32] archon dot saratov at gmail dot com
Description:
------------
bad working a __get method
Test script:
---------------
<?php
class C1 {
protected $arr = array( 'e1' => array() );
public function __get($propertyName) {
if(isset($this->arr[$propertyName])) return $this->arr[$propertyName];
}
public function __set($propertyName, $value) {
if(isset($this->arr[$propertyName])) $this->arr[$propertyName] = $value;
}
}
$c1 = new C1();
var_dump($c1->e1);
$c1->e1[] = 1;
var_dump($c1->e1);
Expected result:
----------------
array
empty
array
empty
Actual result:
--------------
array
empty
( ! ) Notice: Indirect modification of overloaded property C1::$e1 has no effect
in E:\Server\xampp\htdocs\test.php on line 18
array
0 => int 1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55131&edit=1