#45733 [Bgs]: __get, __set error when undefined class member

[email protected] ("twilek at twilek dot hu")
Newsgroups php.bugs
Message-ID <[email protected]>
 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] [email protected]

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.