[prev in list] [next in list] [prev in thread] [next in thread]
List: php-internals
Subject: Re: [PHP-DEV] Assign array with __get
From: "mathieu.suen" <mathieu.suen () easyflirt ! com>
Date: 2010-03-31 14:36:59
Message-ID: 4BB35E0B.4000104 () easyflirt ! com
[Download RAW message or body]
Auke van Slooten wrote:
> Stanislav Malyshev wrote:
>> Hi!
>>
>>> IMHO __get is not consistent at the first place.
>>> on possible example:
>>
>> It is perfectly consistent. You just need to read what it actually does:
>> http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members
>>
>> instead of imagining what it could do.
>
> Hi,
>
> not the same issue, but slightly related, __call() seems to me a bit
> inconsistent with __get(). I'm not sure if this is the right thread to
> ask this in, if not, I'll be happy to take this somewhere else :)
>
> __get is called when accessing any inaccessible property, either when
> not set or when it is private/protected. But __call() only gets called
> when the method is not set, not for private methods. In that case you
> get a Fatal error. e.g:
>
> <?php
>
> class foo {
> protected $foo = 'bar';
>
> function __get($name) {
> return 'getting '.$name."\n";
> }
>
> private function bar() {
> echo 'private bar';
> }
>
> function __call($name, $params) {
> echo 'calling '.$name."\n";
> }
> }
>
> $foo = new foo();
>
> echo $foo->foo;
>
> $foo->bar();
> ?>
>
> Results in:
>
> getting foo
>
> Fatal error: Call to private method foo::bar() from context '' in
> /home/auke/public_html/test/get.php on line 23
>
> I wouldn't mind this if this is how it supposed to work, but the
> documentation uses the same terminology for __get and __call:
>
> "__get() is utilized for reading data from inaccessible properties."
>
> and
>
> "__call() is triggered when invoking inaccessible methods in an object
> context."
>
> In addition the page
> http://www.php.net/manual/en/language.oop5.visibility.php
>
> goes into some detail about when methods are visible and when not,
> making no distinction between methods and properties in regard to
> visibility, and this page is specifically linked from the page about
> overloading, as explaining when __call() should be called:
>
> "The overloading methods are invoked when interacting with properties
> or methods that have not been declared or are not visible in the
> current scope. The rest of this section will use the terms
> "inaccessible properties" and "inaccessible methods" to refer to this
> combination of declaration and visibility. "
>
> So it seems to me that the above code should not have produced a fatal
> error if the documentation is right... or am I misreading something?
>
> regards,
> Auke van Slooten
> Muze
>
IMHO it worth a new thread
-- Mathieu Suen
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic