| Bug #33513 | Fatal error encountered on using Magic method (Overload Section) | ||||
|---|---|---|---|---|---|
| Submitted: | 30 Jun 2005 7:28am UTC | Modified: | 4 Jul 2005 11:06am UTC | ||
| From: | muhamad_zakaria at yahoo dot com | Assigned to: | |||
| Status: | Closed | Category: | Scripting Engine problem | ||
| Version: | 5.1.0-dev | OS: | Windows XP Pro | ||
[30 Jun 2005 10:23am 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
[4 Jul 2005 11:06am 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.

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