Rasmus: On Tue, Apr 24, 2012 at 10:01 PM, Rasmus Schultz <ras...@mindplay.dk> wrote: > I agree, overloading isset() for properties is somewhat creepy - as > that would mean you can no longer rely on isset() to actually work the > way it works for any other value. I understand that's actually the > intent, but I think this would be confusing - isset() is supposed to > behave a certain way depending on the value, and now suddenly it could > return completely arbitrary values unrelated to the value of a > property, breaking established semantics.
There's already an __isset() magic method that does exactly this: http://us2.php.net/manual/en/language.oop5.overloading.php#object.isset In fact, if you take a look at the internal implementation, the return value of __isset is cast to a boolean (via zend_is_true). http://lxr.php.net/opengrok/xref/PHP_5_4/Zend/zend_object_handlers.c#1410 So implementing the isset handler is keeping with the current magic methods... > I would suggest making the unset-method optional for properties, and > the default behavior for unset($time->Hours) would be > $time->Hours=null when no unset-method is implemented. Agree there. The only other sane way of handling that would be to raise an error "trying to unset an accessor property"... Or it would try to unset the true public variable by that name, and hence unsetting nothing... > The "readonly" keyword in my opinion is redundant - properties are > naturally read-only (or write-only) if you implement only the get or > set method, same as any other language. No need to break common > language conventions here. Well, it's redundant for a single class. It's not redundant with inheritance. Otherwise a child class could define a writer for that property, which may be undesirable... Then again, what are the use cases for an enforced read-only (or write only for that matter)...? > RFC looks good though, much better than initial proposals - I like it! :-) Very much agree there... Anthony > - Rasmus > >> From: Anthony Ferrara <ircmax...@gmail.com> >> To: Clint M Priest <cpri...@zerocue.com> >> Cc: "internals@lists.php.net" <internals@lists.php.net> >> Date: Tue, 24 Apr 2012 08:56:55 -0400 >> Subject: Re: [PHP-DEV] RFC: Property get/set syntax (added isset/unset and >> references) >> Clint, >> >> Very nice job overall! Looking quite good. >> >> > Alternatively we could throw an error to a call on isset and/or unset >> > against a property which didn't define an implementation. >> >> I don't care for that concept much. All it's doing is trading one set >> of boilerplate for another. I'd prefer the get() !== null approach, >> since there is a zval allocated for it, so the isset() part. >> >> And I do like the unset overloading, which is right inline with __unset()... > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php