Well, I guess I blinked and missed the internal@ thread on this topic :)

Seriously though, if there was a thread on this subject, please point me in the right direction.

In PHP 5.3 snaps, it appears that magic methods __isset, __unset, __get, __set must have a public visibility or the engine will trigger a warning. Why is this? It works as expected in 5.x branches.

I am not sure why this should be enforced as it should be up to the developer as to which methods in the API should be exposed for direct invocation.

If a developer never intends on a user calling $obj->__set(...), then it should be allowed that the public call to that method be disallowed, but still allow the magic functionality (b/c of the presence of that magic function.)

Without getting too long winded, ill just put code and warnings below.

Cheers,
Ralph Schindler




script.php

<?php

class SomeMagic
{

    public static function getInstance() {}
    protected function __construct() { }
    protected function __isset($name){}
    protected function __unset($name){}
    protected function __set($name, $value){}
    protected function __get($name) {}
    protected function __clone() {}
    protected function __destruct() {}

}

Warnings:

$ /usr/local/php53/bin/php test-magicaccess.php
PHP Warning: The magic method __isset() must have public visibility and can not be static in script.php on line 8 PHP Warning: The magic method __unset() must have public visibility and can not be static in script.php on line 9 PHP Warning: The magic method __set() must have public visibility and can not be static in script.php on line 10 PHP Warning: The magic method __get() must have public visibility and can not be static in script.php on line 11

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to