Drop warning about non-public magic methods

php.internals

Gabriel Caruso

6 years ago
Hello internals, During the development of https://wiki.php.net/rfc/magic-methods-signature I found something that I'd like to share with you, and possibly propose to drop it: there's a warning that php-src throws when a magic method is declared with visibility different than `public`: https://3v4l.org/LKnKB. This warning does not make much sense as the magic method is executed regardless of its visibility. Should it be dropped? - Gabriel Caruso

Josh Bruce

6 years ago
Curious. I tend to follow PSR-12 (with few exceptions): https://www.php-fig.org/psr/psr-12/#44-methods-and-functions <https://www.php-fig.org/psr/psr-12/#44-methods-and-functions> Which requires visibility declaration on all members (methods and properties). Would dropping the requirement make the following impossible: class SomeClass { private function __toString() {} } $instance = new SomeClass(); $instance->__toString(); It’s one thing if PHP can always reach it, it’s a different thing if I, as the developer, can make it so others can’t. Cheers, Josh

Mark Randall

6 years ago
On 13/07/2020 19:32, Gabriel Caruso wrote:
> This warning does not make much sense as the magic method is executed > regardless of its visibility. Should it be dropped?
This seems to be the bigger issue... if something is specified as private, nothing outside its scope has any rights to access it, and that it does feels unexpected. __call should be checked for access IMHO.

Marcio Almada

6 years ago
Hi Grabriel, Hello internals,
> > During the development of https://wiki.php.net/rfc/magic-methods-signature > I > found something that I'd like to share with you, and possibly propose to > drop it: there's a warning that php-src throws when a magic method is > declared with visibility different than `public`: https://3v4l.org/LKnKB. > > This warning does not make much sense as the magic method is executed > regardless of its visibility. Should it be dropped? > > - Gabriel Caruso >
Besides the BC break involved is there any other constraint not to emit a full compile error given that the engine still executes the method call and the visibility, other than public, is therefore invalid code? Ty, Márcio