|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-02-08 08:43 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 17:00:01 2025 UTC |
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)