#45733 [Bgs]: __get, __set error when undefined class member
| From: | twilek at twilek dot hu | Date: | Thu, 07 Aug 2008 08:21:34 +0000 |
| Subject: | #45733 [Bgs]: __get, __set error when undefined class member | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-127709@lists.php.net to get a copy of this message | ||
ID: 45733
User updated by: twilek at twilek dot hu
Reported By: twilek at twilek dot hu
Status: Bogus
Bug Type: Reproducible crash
Operating System: Ubuntu Linux
PHP Version: 5.2.6
New Comment:
This is not bug? then what?
Apache child exit with segmentation fault (11) signal. No error report,
just a white page.
Previous Comments:
------------------------------------------------------------------------
[2008-08-06 14:38:12] lbarnaud@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Using $this->$name in __get() creates an infinite recursion (it calls
__get(), which calls __get(), etc), this is expected.
------------------------------------------------------------------------
[2008-08-06 14:28:02] twilek at twilek dot hu
Description:
------------
When i call the __get or __set with an invalid member variable, the php
interpreter is crash.
If i check the name with isset() then no crash!
PHP Version 5.2.4-2ubuntu5.3 (newest version in ubuntu)
Reproduce code:
---------------
class Test
{
private $mVar = "var";
public function __get( $name )
{
$name = "m" . $name;
// if ( !isset( $this->$name ) ) return ""; //NO CRASH!!
return $this->$name;
}
public function __set( $name, $value )
{
$name = "m" . $name;
// if ( !isset( $this->$name ) ) return; //NO CRASH!!
$this->$name = $value;
echo( "Set: \$this->" . $name . " = " . $value );
}
}
$t = new Test;
echo "Good: " . $t->Var;
echo "Bad: " . $t->Variable;
$t->Variable = "test";
Expected result:
----------------
Good: "var"
Bad: ""
Set: $this->Variable = "test"
Actual result:
--------------
exit signal Segmentation fault (11)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45733&edit=1