#23582 [NEW]: Objects and handles

From: Date: Sun, 11 May 2003 10:18:22 +0000
Subject: #23582 [NEW]: Objects and handles
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39437@lists.php.net to get a copy of this message
From: philip dot nilsson at chello dot se Operating system: Windows XP PHP version: 4.3.2RC2 PHP Bug Type: Class/Object related Bug description: Objects and handles 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 bug report at http://bugs.php.net/?id=23582&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=23582&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=23582&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=23582&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=23582&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=23582&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=23582&r=support Expected behavior: http://bugs.php.net/fix.php?id=23582&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=23582&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=23582&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=23582&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23582&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=23582&r=dst IIS Stability: http://bugs.php.net/fix.php?id=23582&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=23582&r=gnused

« previous php.bugs (#39437) next »