Re: RFC: C-sharp style property get/set syntax for PHP
| From: | president at basnetworks dot net | Date: | Thu, 02 Dec 2010 13:51:00 +0000 |
| Subject: | Re: RFC: C-sharp style property get/set syntax for PHP | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-50817@lists.php.net to get a copy of this message | ||
> 2010/12/1 Richard Quadling <rquadling@gmail.com>
>
>> On 1 December 2010 09:22, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
>> > Hi!
>> >
>> >> Its not a matter of consistency - Properties, as a cross-language
>> concept
>> >> are not meant to work that way. You need to think of a property as a
>> set
>> >
>> > Meant by whom? Is there some law of universe that prevents us from
>> > implementing the feature?
>> >
>> >> of two methods that just have a pretty syntax. Methods cannot be
>> unset,
>> >> and nor should properties be allowed to. isset() should simply tell
>> us
>> >> whether a property with the specified name is part of the class or
>> not.
>> >
>> > If you need methods, why not use methods? If you mimick object
>> properties,
>> > however, it makes sense to make them work exactly like property,
>> otherwise
>> > you have to explain why they don't work this way.
>> >
>> >> isset() in the way you suggest would just be confusing. It would
>> allow
>> is
>> >> to say that a property does not exist, when in fact it does exist.
>> This
>> >> is not logical.
>> >
>> > Sorry, from your answer I don't understand - what happens when you
>> call
>> > isset($foo->property) and unset($foo->property)?
>>
>> If we think of properties as this new entity for the language (rather
>> than somehow massaging existing entities to fit a new usage scenario),
>> then
>>
>> isset($instance->property) will always return true for any defined
>> property. Even if the getter would return null. This is new behaviour
>> and can be easily documented. isset() for a property is more like
>> method_exists() than isset() on a variable.
>> With regard to unset($instance->property), from the manual ...
...
> Why change the expected behavior of isset? If a property has not been set
> then isset must return false, and that includes $foo->name = NULL.
Thats simple then, when isset is invoked, call the get method, and if it
returns null then isset() returns false, but otherwise returns true. That
was likely just a small oversight on Richard's part.
- Dennis