|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-02-09 09:17 UTC] jpauli@php.net
Description:
------------
__invoke() visibility is not honored when indirectly called as $obj().
It is, when directly called, via $obj->__invoke();
Please, note as well that declaring __invoke() as static works as well, I think
it shouldn't (nonsense)
Test script:
---------------
<?php
class Bar {
private function __invoke() {
return __CLASS__;
}
}
$b = new Bar;
echo $b();
/* this works as expected : Fatal Error */
/* echo $b->__invoke(); */
Expected result:
----------------
Call to private method Bar::__invoke() from context ...
Actual result:
--------------
Bar
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 04:00:01 2025 UTC |
I don't think this need to be fixed in this way, like __call: ```php <?php class Bar { private function __call($name, $value) { return __CLASS__; } } $b = new Bar; $b->__call("name", NULL); ``` works well, but with an warning: ``` Warning: The magic method __call() must have public visibility and cannot be static ``` I am not sure whether this is a bug, or just need document.the __toString is more likely: <?php class A { private function __toString() { echo __CLASS__; } } $a = new A; echo $a; echo $a->__toString(); ?> result: PHP Warning: The magic method __toString() must have public visibility and cannot be static in /tmp/1.php on line 3 A PHP Fatal error: Call to private method A::__toString() from context '' in /tmp/1.php on line 10 so, I don't see much problem here, I think we only need a warning is okey. since it's a magic method, not a normal method.