From:             levi at alliancesoftware dot com dot au
Operating system: 
PHP version:      5.0.2
PHP Bug Type:     Zend Engine 2 problem
Bug description:  Nonstatic function can be called as if is static

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 bug report at http://bugs.php.net/?id=31095&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31095&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31095&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31095&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31095&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31095&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31095&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31095&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31095&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31095&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31095&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31095&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31095&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31095&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31095&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31095&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31095&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31095&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31095&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31095&r=mysqlcfg

Reply via email to