Hi!

> I want to do RFS proposal for new language concept - Class extension 
> functions.
> 
> Syntax will looks like:
> 
> function DateTime->localTime() {
>     return $this->format('H:i');
> }

I feel this is inviting trouble. If you need additional functionality,
why not extend the class? Or write a function that accepts DateTime as
an argument? This encourages a style of programming where you never know
which object does what. Even in JS, as far as I know, it's not exactly
the recommended style. But in PHP I don't think we should be doing this.

Moreover, if your method accesses private variables (that's the only
reason why external method can't do the same) then your code needs to
change if private structure of the class changes, which violates
encapsulation. And on top of that we have the same namespacing problems
we've had when we had no namespaces - what if two packages get a bright
idea to define localTime on DateTime? What if they do it in a very
slightly different way?

I think this wouldn't add much what we already can do, but will invite
style of programming that is best avoided.
-- 
Stas Malyshev
smalys...@gmail.com

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

Reply via email to