From:             levi at alliancesoftware dot com dot au
Operating system: 
PHP version:      5CVS-2007-02-08 (CVS)
PHP Bug Type:     Scripting Engine problem
Bug description:  parent and self callback functions erroneously called 
statically

Description:
------------
parent::func() uses a static function call syntax but is 'special' in that
you are allowed to use it to call nonstatic functions without generating
any warnings.

Callbacks with E_STRICT on don't recognise the 'special' nature of
'parent' and 'self'. (happens with call_user_func(),
call_user_func_array(), array_map() etc)

This means that it is impossible to call a parent method through a
callback without generating a warning.


Therefore, code such as:

public function __construct(/* variable argument list */) {
  $args = func_get_args();
  call_user_func_array('parent', '__construct), $args);

  /* ... extra initialisation here ... */
}

will not work with E_STRICT



Note: Related to #36011, but not quite the same (this one involves
inheritance)

Reproduce code:
---------------
#!/usr/local/src/php5/php-5.2.CVS-cgi/sapi/cgi/php -q
<?
error_reporting(E_ALL | E_STRICT);


class Ancestor {
    public function f($a) {
        echo $a;
    }
}

class Descendant extends Ancestor {
    public function f($a) {
    }

    public function g($a) {
        // This is fine
        parent::f($a);

        // This gives a warning
        call_user_func(array('parent', 'f'), $a);

        // This is fine
        self::f($a);

        // This gives a warning
        call_user_func(array('self', 'f'), $a);

        // This is fine
        Descendant::f(4);

        // This gives a warning [probably not avoidable]
        call_user_func(array('Descendant', 'f'), $a);
    }
}

$x = new Descendant();
$x->g(3);

?>

Expected result:
----------------
33

Actual result:
--------------
PHP Strict Standards:  Non-static method [...] cannot be called
statically, assuming $this from compatible context Descendent in
/home/levi/public_html/test2.php5 on line [...]

(See code for which lines generate the warning)

-- 
Edit bug report at http://bugs.php.net/?id=40398&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=40398&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=40398&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=40398&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40398&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=40398&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40398&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40398&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40398&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40398&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40398&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=40398&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=40398&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40398&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40398&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40398&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40398&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40398&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40398&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40398&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40398&r=mysqlcfg

Reply via email to