|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33512 Encountered error on using magic method (Overload Section)
Submitted: 2005-06-30 05:12 UTC Modified: 2005-07-07 18:12 UTC
From: muhamad_zakaria at yahoo dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.0-dev OS: Windows XP Pro
Private report: No CVE-ID: None
 [2005-06-30 05:12 UTC] muhamad_zakaria at yahoo dot com
When we used virtual variables exploiting __set overload method, we encountered errors.

Reproduce code:
	class TheObj {
		public $RealVar1, $RealVar2, $RealVar3, $RealVar4;
		public $Var = array();

		function __set($var, $val) {
			$this->Var[$var] = $val;
		function __get($var) {
			if(isset($this->Var[$var])) return $this->Var[$var];
			else return -1;

	$SomeObj = new TheObj;

	// this will fine
	$SomeObj->RealVar1 = 'somevalue';
	$SomeObj->{'RealVar2'} = 'othervalue';
	$SomeObj->{'RealVar'.(3)} = 'othervaluetoo';
	$SomeObj->{'RealVar'.'4'} = 'anothervalue';

	// this will fine too
	$SomeObj->Virtual1 = 'somevalue';
	$SomeObj->{'Virtual2'} = 'othervalue';

	// it's can't be used since this will encounter error
	$SomeObj->{'Virtual'.(3)} = 'othervaluetoo';
	$SomeObj->{'Virtual'.'4'} = 'anothervalue';

	// but this will fine, ofcourse
	$SomeObj->Var['Virtual'.(3)] = 'othervaluetoo';
	$SomeObj->Var['Virtual'.'4'] = 'anothervalue';

Expected result:
No error when we use below lines:
	$SomeObj->{'Virtual'.(3)} = 'othervaluetoo';
	$SomeObj->{'Virtual'.'4'} = 'anothervalue';
because this should applied fine as we did at "RealVarX" treatments.

Actual result:
Encountered error raises by php.exe


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-04 10:38 UTC] muhamad_zakaria at yahoo dot com
We have tried from the feedback (tony2001), and the raised error is no longer.

But we have another experiences while using 'unset' statement, such as below:
	// we will try to unset these variables

	//the lines below will catch by '__get' magic method since these variables are unavailable anymore
	print $SomeObj->RealVar1."\n";
	print $SomeObj->{'RealVar'.(3)}."\n";

	// now we will try to unset these variables

	//but, these variables are still available??? eventhough they're "unset"-ed
	print $SomeObj->Virtual1."\n";
	print $SomeObj->{'Virtual'.(3)}."\n";
 [2005-07-04 10:51 UTC]
PHP hasn't magic callback to unset overloaded properties.
This is the reason why unset($SomeObj->Virtual1) doesn't work.
 [2005-07-07 18:12 UTC]
Now __unset() and __isset() magic methods are implemented in HEAD.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 18 08:03:35 2021 UTC