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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC