php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33513 Fatal error encountered on using Magic method (Overload Section)
Submitted: 2005-06-30 07:28 UTC Modified: 2005-07-04 11:06 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
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: muhamad_zakaria at yahoo dot com
New email:
PHP Version: OS:

 

 [2005-06-30 07:28 UTC] muhamad_zakaria at yahoo dot com
Description:
------------
Summary:
--------
When we used virtual variables exploiting __get magic method, we received "Fatal error" message.

We have experienced using 'while' loop statement rather than 'foreach' for the example, but it result same fatal error.


Reproduce code:
---------------
	class TheObj {
		public $RealMatArr;
		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->RealMatArr = array(
		"One" => array("11", "12", "13"), 
		"Two" => array("21", "22", "23"), 
		"Three" => array("31", "32", "33"));
	$SomeObj->VirtualMatArr = array(
		"One" => array("11", "12", "13"), 
		"Two" => array("21", "22", "23"), 
		"Three" => array("31", "32", "33"));

	// this will fine too
	foreach($SomeObj->RealMatArr as $indX => $dataX) {
		foreach($dataX as $indY => $dataY) {
			print "RealMatArr[$indX][$indY] = $dataY\n";
		}
	}

	// this will encounter 'Fatal error' message
	foreach($SomeObj->VirtualMatArr as $indX => $dataX) {
		foreach($dataX as $indY => $dataY) {
			print "VirtualMatArr[$indX][$indY] = $dataY\n";
		}
	}

	// but the fatal error will no longer when we modified the lines below:
	$arrval = $SomeObj->VirtualMatArr;
	foreach($arrval as $indX => $dataX) {
		foreach($dataX as $indY => $dataY) {
			print "VirtualMatArr[$indX][$indY] = $dataY\n";
		}
	}

Expected result:
----------------
RealMatArr[One][0] = 11
RealMatArr[One][1] = 12
RealMatArr[One][2] = 13
RealMatArr[Two][0] = 21
RealMatArr[Two][1] = 22
RealMatArr[Two][2] = 23
RealMatArr[Three][0] = 31
RealMatArr[Three][1] = 32
RealMatArr[Three][2] = 33
VirtualMatArr[One][0] = 11
VirtualMatArr[One][1] = 12
VirtualMatArr[One][2] = 13
VirtualMatArr[Two][0] = 21
VirtualMatArr[Two][1] = 22
VirtualMatArr[Two][2] = 23
VirtualMatArr[Three][0] = 31
VirtualMatArr[Three][1] = 32
VirtualMatArr[Three][2] = 33

Actual result:
--------------
RealMatArr[One][0] = 11
RealMatArr[One][1] = 12
RealMatArr[One][2] = 13
RealMatArr[Two][0] = 21
RealMatArr[Two][1] = 22
RealMatArr[Two][2] = 23
RealMatArr[Three][0] = 31
RealMatArr[Three][1] = 32
RealMatArr[Three][2] = 33


Fatal error:  Cannot access undefined property for object with overloaded property access in e:\www\Project1\latihan\obj2.php on line 37

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-30 10:23 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-07-04 11:06 UTC] muhamad_zakaria at yahoo dot com
Summary:
--------
The Fatal error is no longer when we tried from the feedback (tony2001).

But we have another experiences while we applied 'unset' statement such as below:

	// we will try unset these variables, and it's work
	unset($SomeObj->RealMatArr["Two"]);
	unset($SomeObj->RealMatArr["Three"][1]);

	// now we will try unset the whole variable array below
	unset($SomeObj->RealMatArr);

	// ofcourse, this will raises warning since the variable is no longer available (it's work)
	foreach($SomeObj->RealMatArr as $indX => $dataX) {
		foreach($dataX as $indY => $dataY) {
			print "RealMatArr[$indX][$indY] = $dataY\n";
		}
	}

	// then we will try unset these variables, and it's work
	unset($SomeObj->VirtualMatArr["Two"]);
	unset($SomeObj->VirtualMatArr["Three"][1]);

	// then next we will unset the whole of this variable array as below
	unset($SomeObj->VirtualMatArr);

	// but, this will raises no warning as we never unset it before???
	reset($SomeObj->VirtualMatArr);
	while(list($indX, $dataX) = each($SomeObj->VirtualMatArr)) {
		while(list($indY, $dataY) = each($dataX)) {
			print "VirtualMatArr[$indX][$indY] = $dataY\n";
		}
	}

We have no knowledge about the reason, but maybe the reason  is the same as the posted feedback (dmitry) at http://bugs.php.net/bug.php?id=33512.
Thanks.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 18:01:26 2019 UTC