|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-03-26 21:16 UTC] 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] =>
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 09:00:01 2025 UTC |
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) { ....