Edit report at http://bugs.php.net/bug.php?id=51406&edit=1
ID: 51406 Updated by: [email protected] Reported by: sommertm at gmail dot com Summary: Exception constructor calling method statically populates $this -Status: Open +Status: Bogus Type: Bug Package: *General Issues Operating System: Windows Server 2008 PHP Version: 5.3.2 New Comment: This is due to compatibility to a flaw of PHP 4. You have to mark your method explicitly static to prevent that: public static function Write($string) { .... Previous Comments: ------------------------------------------------------------------------ [2010-03-26 21:16:15] sommertm at gmail dot com Description: ------------ You are able to call a class method statically even if it is not defined as static. If you do this from the constructor of an Exception, $this references the Exception object. This is tested on my dev machine running Windows 7, IIS7.5 and PHP 5.3.2 as well as our test server running Windows Server 2008, IIS7 and PHP 5.3.2 Test script: --------------- <?php class ExtendedException extends Exception { public function __construct($message, $code) { parent::__construct($message, $code); Log::Write("Hello!"); } } class Log { // Note this method is not marked static public function Write($string) { print_r($this); } } try { throw new ExtendedException(); } catch (Exception $e) { } ?> Expected result: ---------------- Actual result: -------------- ExtendedException Object ( [message:protected] => [string:Exception:private] => [code:protected] => 0 [file:protected] => D:\Public\Innovirt\bugtest.php [line:protected] => 18 [trace:Exception:private] => Array ( ) [previous:Exception:private] => ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51406&edit=1
