php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38640 Fatal error while get unsetted property.
Submitted: 2006-08-29 10:02 UTC Modified: 2006-11-29 22:12 UTC
From: ruslan dot kyrychuk at gmail dot com Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.5 OS: Windows 2003, XP
Private report: No CVE-ID: None
 [2006-08-29 10:02 UTC] ruslan dot kyrychuk at gmail dot com
Description:
------------
When unsetting object property it unsetted from object then __get method of object is called while accessing it.

Besides property exists in all reflection objects (ReflectionObject and ReflectionProperty) but cause Fatal error while getting it.

Reproduce code:
---------------
<?php
class B{}
class A
{
	public $Var = null;
	public function __construct()
	{
		$this->Var= new B();
	}
	public function __get($name)
	{
		echo "get {$name}\n";
		if(isset($this->Var))
		{
			return $this->Var;
		}
		else
		{
			echo "Undefined variable\n";
			return null;
		}
	}
	public function __unset($nm)
	{
		echo "unset";
	}
}

$a = new A();
unset($a->Var);
$o = new ReflectionObject($a);
$p = $o->getProperty('Var');
Reflection::export($o);//Variable Exists
Reflection::export($p);//Variable Exists
var_dump($a->Var);//__get called 
var_dump($p->getValue($a)); //Fatal error
?>

Expected result:
----------------
$o = new ReflectionObject($a); 
has correct current instance properties or
$p->getValue($a) - will call __get method too and not cause fatal error.

Actual result:
--------------
Object of class [ <user> class A ] {
  @@ D:\WWW\www.usoftinc.com\test2.php 3-27

  - Constants [0] {
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [1] {
    Property [ <default> public $Var ]
  }

  - Dynamic properties [0] {
  }

  - Methods [3] {
    Method [ <user, ctor> public method __construct ] {
      @@ D:\WWW\www.usoftinc.com\test2.php 6 - 9
    }

    Method [ <user> public method __get ] {
      @@ D:\WWW\www.usoftinc.com\test2.php 10 - 22

      - Parameters [1] {
        Parameter #0 [ <required> $name ]
      }
    }

    Method [ <user> public method __unset ] {
      @@ D:\WWW\www.usoftinc.com\test2.php 23 - 26

      - Parameters [1] {
        Parameter #0 [ <required> $nm ]
      }
    }
  }
}

Property [ <default> public $Var ]

get Var
Undefined variable
NULL

<br />
<b>Fatal error</b>:  Internal error: Could not find the property Var in <b>test2.php</b> on line <b>36</b><br />


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-29 11:08 UTC] tony2001@php.net
Assigned to the maintainer.

Marcus, please take a look at this patch:
http://tony2001.phpclub.net/dev/tmp/bug38640.diff

I don't want to commit it when you're still on vacation, since I don't understand what was the original idea behind getValue/setValue - it seems quite obvious that they must use getter/setter, but for some reason they don't.
The patch changes both of them to use appropriate engine calls.
 [2006-11-29 22:12 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Looks like I committed the patch and forgot to close report.
Anyway, it works fine now.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 19 06:00:03 2025 UTC