ID: 36214 Updated by: [EMAIL PROTECTED] Reported By: pexu at lyseo dot edu dot ouka dot fi Status: Open Bug Type: Scripting Engine problem Operating System: Windows XP PHP Version: 5.1.3-dev Assigned To: dmitry New Comment:
As a confirmation of the reference problem, it works using an object (ArrayObject): $ctx->comment_preview = new ArrayObject(); $ctx->comment_preview['content'] = ''; $ctx->comment_preview['rawcontent'] = ''; $ctx->comment_preview['name'] = ''; $ctx->comment_preview['mail'] = ''; $ctx->comment_preview['site'] = ''; $ctx->comment_preview['preview'] = false; $ctx->comment_preview['remember'] = false; var_dump($ctx); It is getting rather confusing for the users. The bad point is this specific case is that ArrayObject is disabled with --disable-all... Previous Comments: ------------------------------------------------------------------------ [2006-11-28 03:24:31] [EMAIL PROTECTED] Is it the same issue? I suspect it to be the same but I'm unsure about the bogus state. I would like to have a little explanation, just to write a good work around if this is not a bug. In this example, the first init raises a notice "Indirect modification of overloaded property context::$attachments has no effect" as the second works like a charm. class context { public $stack = array(); public function __set($name,$var) { $this->stack[$name] = $var;return; } public function __get($name) { if (!isset($this->stack[$name])) { return null; } return $this->stack[$name]; } } $ctx = new context; $ctx->comment_preview = array(); $ctx->comment_preview['content'] = ''; $ctx->comment_preview['rawcontent'] = ''; $ctx->comment_preview['name'] = ''; $ctx->comment_preview['mail'] = ''; $ctx->comment_preview['site'] = ''; $ctx->comment_preview['preview'] = false; $ctx->comment_preview['remember'] = false; var_dump($ctx); $comment_preview = array(); $comment_preview['content'] = ''; $comment_preview['rawcontent'] = ''; $comment_preview['name'] = ''; $comment_preview['mail'] = ''; $comment_preview['site'] = ''; $comment_preview['preview'] = false; $comment_preview['remember'] = false; $ctx->comment_preview = $comment_preview; var_dump($ctx); ------------------------------------------------------------------------ [2006-02-10 17:42:36] pexu at lyseo dot edu dot ouka dot fi Sure it doesn't return a reference, but why this example still prints "5.1.3-dev This shouldn't work, but why are you seeing this text?"? <?php class a { public $cond_oper = false, $array = array(); public function __set ($key, $value) { return $this->array[$key] = $value; } public function __get ($key) { if ($this->cond_oper) return true ? $this->array[$key] : null; else return $this->array[$key]; // This one works even though it shouldn't! } } $a = new a; $a->a = array(); $a->a[] = "This shouldn't work, but why are you seeing this text?"; $a->cond_oper = true; $a->a[] = "Nope, this text won't be displayed (which is ok)."; echo phpversion(), "\n", array_pop($a->a); ?> If I understood your explanations correctly, $a->a should've been an empty array and I should've seen two error messages telling me that __get method didn't return a reference etc. PHP snapshot I used was built on Feb 10, 2006 15:30 GMT. ------------------------------------------------------------------------ [2006-02-06 10:32:25] [EMAIL PROTECTED] This is not a bug. Method __get() returns by value and it's result cannot be passed by reference. ------------------------------------------------------------------------ [2006-02-04 00:01:14] pexu at lyseo dot edu dot ouka dot fi I quickly tried the newest snapshot (20060203, 5.1.3-dev) but neither error messages were generated nor results were any different from 5.1.2. (Error_reporting was set to E_ALL | E_STRICT and display_errors was turned on. I tried both conditional operator and normal if clause.) But I guess I can utilize ArrayObject etc. to get the expected result I wanted. ------------------------------------------------------------------------ [2006-02-02 16:04:32] [EMAIL PROTECTED] That it works in the latter case is just a side affect which falls under "undefined behaviour". You should actually see an error telling you that __get() can't return a reference or that array_push() wants a reference. IIRC it's fixed in current CVS, could you please try? Where "fixed" means that an error is generated. Thanks. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/36214 -- Edit this bug report at http://bugs.php.net/?id=36214&edit=1