#29767 [Opn]: Weird behaviour of __set($name, $value);

From: Date: Fri, 20 Aug 2004 02:52:47 +0000
Subject: #29767 [Opn]: Weird behaviour of __set($name, $value);
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-64987@lists.php.net to get a copy of this message
ID: 29767 User updated by: morten at nilsen dot com Reported By: morten at nilsen dot com Status: Open Bug Type: Zend Engine 2 problem Operating System: Linux PHP Version: 5.0.1 New Comment: further weirdness uncovered with this code; <?php class test { function __set($name, $value) { $name = $name.$value; echo "$name<br>"; } } $test = new test; $test->kake = 1; $test->kake = 2; $a = 3; $test->kake = $a; $a++; $test->kake = $a; for($a = 0; $a < 10; ++$a) $test->kake = $a; ?> Previous Comments: ------------------------------------------------------------------------ [2004-08-20 04:16:34] morten at nilsen dot com (obvious) workaround is to change: if($name[0] != '&') $name = '&'.$name.';'; into: $entity = "&$name;"; ------------------------------------------------------------------------ [2004-08-20 03:55:51] morten at nilsen dot com Description: ------------ The attached script behaves ilogically Reproduce code: --------------- <?php class template { function __set($name, $value) { echo "Set $name to $value<br>"; if($name[0] != '&') $name = '&'.$name.';'; } } function fetchlist($name) { global $template; echo '$template->what = '.$name.'<br>'; $template->what = $name; } $template = new template(); fetchlist('user'); fetchlist('group'); ?> Expected result: ---------------- $template->what = user Set what to user $template->what = group Set what to group Actual result: -------------- $template->what = user Set what to user $template->what = group Set &what; to group ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29767&edit=1

« previous php.bugs (#64987) next »