php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33314 Child class variable change not propogated during function call
Submitted: 2005-06-12 00:01 UTC Modified: 2007-07-19 19:49 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: gregory dot szorc at case dot edu Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2005-06-12 OS: Linux (multiple)
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: gregory dot szorc at case dot edu
New email:
PHP Version: OS:

 

 [2005-06-12 00:01 UTC] gregory dot szorc at case dot edu
Description:
------------
A method is called on an instance of a class which is derived from a chain of derived classes, some abstract.  The method is defined in the base class and this method alters a variable also defined in the base class.  When the method is called, the object is unchanged.

During debugging, the variable is actually changed by the base method.  However, this change of variable is not propogated down into the derived classes.

When the base method is changed so that it changes another variable in the base class, the changes are reflected after the method is called.

In summary, a function call does not produce an obvious change of variable.  When the function is changed so it alters another variable on top of the original, both changes are seen after the function call.

Reproduce code:
---------------
I have been unable to reproduce this code outside of the project in which I discovered the bug.

To obtain the code, use subversion:

`svn co -r 119 http://zorro.case.edu/svn/repos/php_classes/File_iCal/trunk/ iCal`

Use might need to add the created directory to the PHP include path for the code to run.

Read File/iCal/BaseComponent.php at line 234 for info on how to reproduce.



Expected result:
----------------
A variable gets changed via function call.

Actual result:
--------------
The variable appears left unchanged unless the function definition itself is changed so that the object is further modified.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-12 02:10 UTC] sniper@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-06-14 16:07 UTC] gregory dot szorc at case dot edu
I have compiled the latest 5.1 CVS snapshot from June 14, 2005 
and the problem persists.
 [2005-06-14 16:47 UTC] sniper@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-06-14 16:58 UTC] gregory dot szorc at case dot edu
As mentioned in the orignal post, I have not been able to 
reproduce the problem outside of the project from which I am 
working.  Believe me, I tried.  Read http://zorro.case.edu/
viewcvs/php_classes/File_iCal/trunk/File/iCal/
BaseComponent.php?rev=119&view=markup around line 234 for a 
comment and the actual code that causes the bug to trigger.

Given the way that the problem can be "solved," there is 
obviously a bug with the class support.  Unfortunately, I 
can't reproduce it outside of the PEAR project on which I am 
working.
 [2005-06-15 15:30 UTC] sniper@php.net
We _REALLY_ need a short reproducing script. We don't have time to go through hundreds of lines of code..

 [2005-06-15 16:11 UTC] gregory dot szorc at case dot edu
I have tried to recreate the problem by recreating the basic 
class hierarchy that exists in my project.  Unfortunately, I 
have been unable to duplicate.  I would gladly try and debug 
things myself, but I have no knowledge regarding debugging 
core PHP.

The problem occurs in BaseLayout.php.  It is reproducable 
through tests/iCal_create.php.  The test program doesn't 
even involve a lot of the classes.  Considering that the 
problem is an object reference being lost/ignored as it is 
passed back to a function, I would think this would be a 
relatively easy problem to debug.  Who knows.

If someone could provide instructions for how to debug this 
problem, I would attempt to do it myself.
 [2005-06-15 18:14 UTC] tony2001@php.net
Gregory, if you provide an example (even relatively big) it would be MUCH easier for us to understand what are you talking about (and to fix it too). 
Please cook a script (okay, let it be BIG script), put it somewhere on the Net (no SVN and other exotic things please, just a plain HTTP) and give us the link. 
Thanks in advance. 
 [2005-06-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-12-14 07:55 UTC] andrew at azarov dot com
class.php:
<?
class Test 
{
	var $Dynamic = Array();
	function Start()
	{
                $Dynamic = Array("test"=>"hope")
		$this->$Dynamic = $Dynamic;
	}
        function GetArray()
        {
                return $this->Dynamic;
        }
}
?>
test.php:
<?
require class.php;
$file = new Test();
$file->Start();
print_r($file->Dynamic); // Will result in 'Array()'
$s = $file->GetArray(); // Will result in 'Fatal error: Cannot access empty property'
print_r($s)
?>
 [2007-02-06 01:08 UTC] xstex2 at hotmail dot com
Any update on this issue?
 [2007-02-06 03:44 UTC] confins_de_l_univers at yahoo dot fr
I think it's a typo error.

In the Start() method, he use :
$this->$Dynamic = $Dynamic;

but he should use :
$this->Dynamic = $Dynamic;

so $this->Dynamic is not set when he call GetArray() method
 [2007-02-06 03:55 UTC] gregory dot szorc at case dot edu
As the original reporter of the bug, I would just as soon close it.  I cannot reproduce it outside of the code originally used (I don't even know if I have a copy of that any more).  Since no reproduce exists, perhaps it is just best to close and see if the problem resurfaces at a later date.
 [2007-07-19 19:49 UTC] jani@php.net
Ok, if you can reproduce, reopen.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 12:01:30 2024 UTC