Bug #65042 [Opn]: Protected, private __invoke() magic method raises Warning
| From: | bjori@php.net | Date: | Sun, 16 Jun 2013 18:14:40 +0000 |
| Subject: | Bug #65042 [Opn]: Protected, private __invoke() magic method raises Warning | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9945@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
Updated by: bjori@php.net
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:
See also bug#61025
Previous Comments:
------------------------------------------------------------------------
[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