php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45733 __get, __set error when undefined class member
Submitted: 2008-08-06 14:28 UTC Modified: 2008-08-07 08:21 UTC
From: twilek at twilek dot hu Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.6 OS: Ubuntu Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: twilek at twilek dot hu
New email:
PHP Version: OS:

 

 [2008-08-06 14:28 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-06 14:38 UTC] 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-07 08:21 UTC] twilek at twilek dot hu
This is not bug? then what?
Apache child exit with segmentation fault (11) signal. No error report, just a white page.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 02:01:35 2025 UTC