Bug #51406 [Opn->Bgs]: Exception constructor calling method statically populates $this
| From: | johannes@php.net | Date: | Fri, 02 Apr 2010 10:51:25 +0000 |
| Subject: | Bug #51406 [Opn->Bgs]: Exception constructor calling method statically populates $this | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-149273@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51406&edit=1
ID: 51406
Updated by: johannes@php.net
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