ID: 31095
Updated by: [EMAIL PROTECTED]
Reported By: levi at alliancesoftware dot com dot au
-Status: Open
+Status: Verified
Bug Type: Zend Engine 2 problem
PHP Version: 5.0.2
Previous Comments:
------------------------------------------------------------------------
[2004-12-14 23:59:10] levi at alliancesoftware dot com dot au
Description:
------------
If you call a member function in another class, it succeeds and
$this is set to the *calling* class. The new PHP 5 object model should
make the function inaccessible, unless
[a] It is a static function ($this should be unset)
[b] It is an ancestor class of the calling class ($this should be
set)
[c] PHP 4 compatibility is on ($this should be set)
At the very minimum, this should generate an error in strict mode.
This may have been the expected behaviour in PHP 4, but PHP 5 has a
static keyword for exactly this situation now. Note: This was reported
in PHP4 under bugs #19384 and #12622 and was (incorrectly) claimed to
have been fixed in #19194 (it still occurs in 4.3.4)
Note: Currently, $this is unset if
[a] you call a global (non class) function
[b] otherClassMethod() is declared static
Reproduce code:
---------------
#!/usr/local/bin/php -qC
<?
error_reporting(E_ALL | E_STRICT);
class OtherClass {
public function otherClassMethod() {
echo "Called otherClassMethod() from within class ".
get_class($this)."\n";
}
}
class NormalClass {
public function __construct() {
OtherClass::otherClassMethod();
}
}
new NormalClass();
?>
Expected result:
----------------
PHP Notice: Undefined variable: this in testStatic2.php5 on line 7
(or even better):
PHP Notice: Calling nontstatic function as static in testStatic2.php5
on line 14
Actual result:
--------------
Called otherClassMethod() from within class NormalClass
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31095&edit=1