On Tue, Sep 17, 2013 at 7:50 PM, Stuart Langley <slang...@google.com> wrote:
> To be honest, looking at the example in the RFC, being able to define a
> member function 'new' on a class that completely changes the semantics of
> the new operator is a great example of why you would not want this feature.
>
It doesn't change anything because $foo->new() has no intrinsic
meaning in PHP. And I don't think the argument "the programmer might
do something stupid" ever holds much weight as a no vote against
anything. If somebody wants to create a confusing misnomer, he doesn't
need this proposed feature to do so.

But I agree that the RFC is missing any real-world examples of why it
might be useful, and that any new language feature should have
real-world benefits. Hopefully some more compelling reasons will be
added to the RFC.

Here's something that I've personally done with much shame:

class Where
{
  private function _or($lhs, $op = null, $rhs = null)
  {
  }

  public function __call($func_name, $args)
  {
    if ($func_name == 'or')
      return call_user_func_array([$this, '_or'], $args);
  }
}

$query->where('foo', '=', 1)->or('bar', '=', 2);

Imagine that $query->where() returns a Where object. I really want an
"or" method because it make things concise & readable, but this is not
allowed. So I override the __call method to add such functionality,
which adds useless overhead.

There are a few keywords, such as list and unset, that I often wish I
could use in PHP. So in terms of readability, I think any sane
programmer would use this proposed functionality for good...

--
Matthew Leverton

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

Reply via email to