ID: 34467 Updated by: [EMAIL PROTECTED] Reported By: stochnagara at hotmail dot com -Status: Open +Status: Feedback Bug Type: Class/Object related PHP Version: 5CVS-2005-09-11 (snap) New Comment:
Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If possible, make the script source available online and provide an URL to it here. Try to avoid embedding huge scripts into the report. Previous Comments: ------------------------------------------------------------------------ [2005-09-11 22:27:25] stochnagara at hotmail dot com Description: ------------ There is some incostistency with foreach and a class which has __get and __set methods. I don't know what is the intended behaviour but there is a problem there when assigning a foreach key or value to an overloaded member of such class. See comments in the expected result region. Reproduce code: --------------- <? class abc { function __set ($key, $value) { echo "__set ($key,$value)<br/>"; $this->arr[$key] = $value; } function /*&*/ __get ($key) { echo "__get ($key)<br/>"; return $this->arr[$key]; } function __isset ($key) { echo "__isset ($key)<br/>"; return isset ($this->arr[$key]); } function __unset ($key) { echo "__unset ($key)<br/>"; unset ($this->arr[$key]); } private $arr; } $abc = new abc(); foreach (array (1,2,3) as $abc->k => $v) { print_r($abc);echo ';'; var_dump($abc->k);echo ';'; } $abc->k = 4; echo '-----<br/>'; foreach (array (1,2,3) as $abc->k => $v) { print_r($abc);echo ';'; var_dump($abc->k);echo ';'; } echo '<br/>-----<br/>'; $abc_value = new abc(); foreach (array (1,2,3) as $v => $abc_value->k) { print_r($abc_value);echo ';'; var_dump($abc_value->k);echo ';'; } Expected result: ---------------- Depends of specification. Case 1 : First foreach fills $arr with keys. Others are ok. Case 2 : Second foreach does not fill $arr with keys. Note 1! When __get is changed to return by reference, first foreach behaves exactly like the second one. Note 2! Third foreach calls __set while first and second do not. Actual result: -------------- __get (k) abc Object ( [arr:private] => Array ( ) ) ;__get (k) NULL ;__get (k) abc Object ( [arr:private] => Array ( ) ) ;__get (k) NULL ;__set (k,4) ----- __get (k) abc Object ( [arr:private] => Array ( [k] => 0 ) ) ;__get (k) int(0) ;__get (k) abc Object ( [arr:private] => Array ( [k] => 1 ) ) ;__get (k) int(1) ; ----- __set (k,1) abc Object ( [arr:private] => Array ( [k] => 1 ) ) ;__get (k) int(1) ;__set (k,2) abc Object ( [arr:private] => Array ( [k] => 2 ) ) ;__get (k) int(2) ; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34467&edit=1