#36571 [NEW]: __set() affects outer variable when overloading with "[]=" and "{}="
| From: | cid73 at 163 dot com | Date: | Wed, 01 Mar 2006 13:55:50 +0000 |
| Subject: | #36571 [NEW]: __set() affects outer variable when overloading with "[]=" and "{}=" | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-93801@lists.php.net to get a copy of this message | ||
From: cid73 at 163 dot com
Operating system: WinXP SP2
PHP version: 5.1.2
PHP Bug Type: Scripting Engine problem
Bug description: __set() affects outer variable when overloading with "[]=" and
"{}="
Description:
------------
I'm not sure if there are inner operaters named "[]=" or "{}=", but it
really goes wrong when overloading such operations.
Here's some demo code.
Reproduce code:
---------------
class Setter
{
private $attributes;
public function __construct($attributes) {
$this->attributes = $attributes; }
private function __set($var, $value) {
$this->attributes[$var] = $value; }
private function __get($var) {
if ( isset($this->attributes[$var]) ) {
return $this->attributes[$var]; }
else {
return null; }}
}
$a = array('a' => array('a', 'b', 'c'), 'b'
=> 'Hello');
$o = new Setter($a);
$o->a[0] = 'A';
$o->a[] = 'd';
$o->b{0} = 'h';
print_r($a); // gotta check $a, $o is good
/* ouputs:
Array
(
[a] => Array
(
[0] => A
[1] => b
[2] => c
[3] => d
)
[b] => hello
)
*/
Expected result:
----------------
$a is unchangeable at the moment
Actual result:
--------------
$a was modified
--
Edit bug report at http://bugs.php.net/?id=36571&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36571&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36571&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36571&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36571&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=36571&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36571&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36571&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36571&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36571&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36571&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=36571&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=36571&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36571&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36571&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36571&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36571&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36571&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36571&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36571&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36571&r=mysqlcfg