Doc #65042 [PATCH]: Protected, private __invoke() magic method raises Warning

From: Date: Sun, 30 Dec 2018 14:50:20 +0000
Subject: Doc #65042 [PATCH]: Protected, private __invoke() magic method raises Warning
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16257@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 Patch added by: girgias@php.net Reported by: pha dot bridgman at gmail dot com Summary: Protected, private __invoke() magic method raises Warning Status: Assigned Type: Documentation Problem Package: Class/Object related Operating System: Debian 7.0 PHP Version: 5.5.0RC3 Assigned To: laruence Block user comment: N Private report: N New Comment: The following patch has been added/updated: Patch Name: magic-method-must-constant Revision: 1546181419 URL: https://bugs.php.net/patch-display.php?bug=65042&patch=magic-method-must-constant&revision=1546181419 Previous Comments: ------------------------------------------------------------------------ [2013-06-16 20:19:39] pha dot bridgman at gmail dot com Point taken with regard to consistency; perhaps I would have better expressed myself by saying that allowing magic methods with restricted visibility would be more consistent with the expected operation of class methods. I understand from reading bug #61025 that in 5.5 (as in previous versions) these magic methods are forcibly public; perhaps as a future project the ability to restrict their visibility could be realised. ------------------------------------------------------------------------ [2013-06-16 18:14:40] bjori@php.net See also bug#61025 ------------------------------------------------------------------------ [2013-06-16 18:10:24] bjori@php.net zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static"); zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __call() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static"); zend_error(E_WARNING, "The magic method __get() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __set() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __unset() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __isset() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static"); zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static"); ------------------------------------------------------------------------ [2013-06-16 16:57:17] pha dot bridgman at gmail dot com 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. ------------------------------------------------------------------------ [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 (#16257) next »