Bug #65042 [Com]: Protected, private __invoke() magic method raises Warning

From: Date: Sun, 16 Jun 2013 16:57:17 +0000
Subject: Bug #65042 [Com]: Protected, private __invoke() magic method raises Warning
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9943@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65042&edit=1 ID: 65042 Comment by: pha dot bridgman at gmail dot com Reported by: pha dot bridgman at gmail dot com Summary: Protected, private __invoke() magic method raises Warning Status: Open Type: Bug Package: Documentation problem Operating System: Debian 7.0 PHP Version: 5.5.0RC3 Block user comment: N Private report: N New Comment: Is this really a documentation problem? That would imply that it is intended behaviour for the __invoke() method to always be public! It seems odd that a restriction should be made such that it couldn't have a restricted visibility, like __construct. In terms of backwards compatibility, if people have been using protected __invoke() methods (because the documentation said they could), 5.5 will now cause warnings, whilst also precluding that functionality. If the alternative, i.e., making the visibility be honoured properly, was employed, then all code would function as intended... and we would see more consistency in magic methods. Previous Comments: ------------------------------------------------------------------------ [2013-06-15 18:40:19] pha dot bridgman at gmail dot com Description: ------------ Definition of a non-public __invoke() magic-method in a class raises a warning. PHP 5.4 did not exhibit this behaviour, and the manual (http://www.php.net/manual/en/language.oop5.magic.php#object.invoke) does not stipulate that the __invoke() magic-method must be public. Test script: --------------- <?php class test { public function __construct() { $this(); } protected function __invoke() { echo PHP_VERSION; } } new test; ?> Expected result: ---------------- peter@xenon:~/build$ php ~/test/invoke.php 5.4.4-14 Actual result: -------------- peter@xenon:~/build/php-5.5.0RC3$ sapi/cli/php ~/test/invoke.php Warning: The magic method __invoke() must have public visibility and cannot be static in /home/peter/test/invoke.php on line 10 5.5.0RC3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65042&edit=1

« previous php.doc.bugs (#9943) next »