php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22367 undefined variable has a value
Submitted: 2003-02-21 17:31 UTC Modified: 2003-08-26 23:24 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:3 (75.0%)
From: stanislav dot chachkov at epfl dot ch Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.3.0 OS: Solaris8
Private report: No CVE-ID:
 [2003-02-21 17:31 UTC] stanislav dot chachkov at epfl dot ch
In a method we have that ($a is undefined,
but this also works if you substitute $a by any other name):

function getColumnValue($col_name){
  var_dump($a); echo "a=$a  <br>";
  ...
}


This method is called a number of times and the output is like this:

NULL a=
NULL a=
...
NULL a=Etape_Editor_IDEtape_Editor_ID''

Actually "EtapeEditor_ID" was the parameter of PREVIOUS call to one of methods of this class. 
 
I can not reproduce this problem with a short script, it seems that it appears only when the number of classes, objects and calls is large, otherwise it works fine.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-23 13:16 UTC] stanislav dot chachkov at epfl dot ch
This is the test case:

<?
class A{
  var $fields;
  
  function getID(){
    return $this->getColumnValue($this->getPK());
  }
  
  function getColumnValue($col_name){
    return $this->fields[$col_name];
  }
  
 
  function save(){
    $this->getID();
    $i=333;
    echo "Dump of z: ";
    var_dump($z);
    echo "<br>z=";
    echo $z;
    echo "<br>";
    if($boo){
      echo "undefined is now defined<br>";
    }else{
      echo "undefined is undefined<br>";
    }
    
    $s1="YES";
    $s2="NO";
    
    echo "s1=$s1, s2=$s2";
  }
}


class B extends A{
  function getPK(){
    return "ID";
  }
  
  function &getColumnValue($col_name){
    return parent::getColumnValue($col_name);
  }
}


$b=new B();
if(!$b->getID()){}
$b->save();

?>

The output that we have is:

Dump of z: NULL
z=333
undefined is now defined
s1=NO, s2=NO
 [2003-02-24 15:11 UTC] stanislav dot chachkov at epfl dot ch
We found a workaround: getColumnValue functions should both return a reference or both return a value. 
Actually it is also possible to return a reference from class A and value from sub class B, but the inverse breaks the stack.
 [2003-03-24 04:31 UTC] moriyoshi@php.net
Related to bug #22836
 [2003-08-26 23:24 UTC] sniper@php.net
This is fixed in PHP 5, won't be fixed in PHP 4.

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 03:01:55 2014 UTC