Bug #14582: initializing with NULL reference

From: Date: Tue, 18 Dec 2001 16:11:08 +0000
Subject: Bug #14582: initializing with NULL reference
Groups: php.dev 
Request: Send a blank email to php-dev+get-74262@lists.php.net to get a copy of this message
From: zork@clan.pl Operating system: slackware linux 8.0 PHP version: 4.1.0 PHP Bug Type: Scripting Engine problem Bug description: initializing with NULL reference I've encountered stack problem. Here is simplest code, that reproduces this: <?php class CForm { var $inputs; function Cform() { $this -> inputs = array(); } function &get_input($name) { return($this -> inputs[$name]); } }; class Cinput_select { var $values; var $name; function Cinput_select($t) { $this -> name = $t; $this -> options = array(); } function add_value($value) { $this -> values[] = $value; } }; $form = new CForm(); //coment next two lines and new returns NULL $sel = new CInput_select("b"); $sel -> add_value("a"); $a =& $form -> get_input("a"); var_dump($a); $sel = new CInput_select("test"); var_dump($sel); $sel -> add_value("a"); ?> After call to CForm::get_input() $a is not a registered variable. Later new returns corrupted structure. If you comment out first two lines of program new returns NULL. In my original source code even when I created object using diffrient name after assigning NULL reference to variable new still corupts some of my variables. I think its becouse $a doesn't have storage on stack but interpreter thinks that it has. I think that returning NULL reference should initialize variable to false. This is code is not good programming pracitce and could be easily ommited, but taht doesn't change the fact that this is a bug. regards Lukasz Michalski -- Edit bug report at: http://bugs.php.net/?id=14582&edit=1

« previous php.dev (#74262) next »