#23582 [Opn->Bgs]: Objects and handles

From: Date: Sun, 11 May 2003 10:34:31 +0000
Subject: #23582 [Opn->Bgs]: Objects and handles
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39438@lists.php.net to get a copy of this message
ID: 23582 Updated by: wez@php.net Reported By: philip dot nilsson at chello dot se -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Windows XP PHP Version: 4.3.2RC2 New Comment: $this->$file should be $this->file. Please read the section on variable variables in the manual. User error -> bogus. Previous Comments: ------------------------------------------------------------------------ [2003-05-11 05:18:22] philip dot nilsson at chello dot se This bug resembles http://bugs.php.net/bug.php?id=23576, but I am not really sure if they are the same. First, I'll show a working(or not working, :)) example: -------- class CTest { var $filename; var $file; function CTest() { $this->$filename = 'data/data.txt'; } function Write($data1, $data2) { $data[] = array($data1, $data2); $this->$file = fopen($this->$filename, 'w'); for ($i = 0; $i < count($data); $i++) fwrite($this->$file, implode('||', $data[$i])); fclose($this->$file); } } $test = new CTest(); print('<pre>'); print_r($test); print('</pre>'); $test->Write('data', 'moredata'); print('<pre>'); print_r($test); print('</pre>'); -------- And the output: -------- ctest Object ( [filename] => [file] => [] => data/data.txt ) ctest Object ( [filename] => [file] => [] => Resource id #1 ) -------- And the output I expected: -------- ctest Object ( [filename] => data/data.txt [file] => empty, maybe? ) ctest Object ( [filename] => data/data.txt [file] => Resource id #1 ) -------- As you can see the class members gets changed. If I remove the constructor, the empty [] variable disappears, but the variables still gets messed up. This behaviour is completely unexpected, and also totally illogical. I don't think this bug affects objects that do not use handles, but it might. And I haven't tested it on Linux yet, but I do not think it would work there either. This bug has been in PHP at least a couple versions as I remember it from about a year ago, I tried to make a class that would handle my database connections, but the handle got invalid after the first use. Fixing it would be really nice. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23582&edit=1

« previous php.bugs (#39438) next »