I'll respond to all at once ;)

On 11/30/11 1:58 PM, Will Fitch wrote:
If that's the case, then why not just add whatever $options is as a
parameter to your constructor.  I'm not totally against this concept,
but this use is moot.


I'm simply trying to find usefulness in the new feature of

    $x = (new Foo)->bar();

That's not useful to me. Mainly b/c if you don't get a handle on the object, what was the point in the first place?

PHP already has a place for this in functions, static methods, AND if you're idea of OO programming is wrapping stateless functions in classes for "grouping" - in namespaces.


On 11/30/11 1:13 PM, Nikita Popov wrote:
The plain (new Foo)->bar() syntax*is*  useful for cases like (new
ReflectionClass($class))->implementsInterface('Foo'), where you need
only one single bit of information from a class.


Sure that is useful.. Although that looks more to me like an edge case than my idea of how expression-dereferencing would work. Like I said above, if your object doesn't do much more than what a function would do, why not just file a feature request for Reflection to have a factory method on every class?

  ReflectionClass::factory($class)->implementsInterface('Foo');
  // or fix is_subclass_of($classname, $interfacename) ;)

Do we really want to encourage people to create objects for the purpose of calling a single method and tossing away the original object? You'd be better off using a function or a static method if that is what you want. Furthermore, if you want to chain methods, that is also dangerous since PHP cannot do type enforcement on return values. So,

  $instanceOfFooOrCoolResult = (new $foo)->do()->something()->cool();

needs to somehow guarantee that all methods of the type $foo will return $this. (BTW, this is not an argument for my feature as much as its an argument as much as its one for "if we're going to do something, why not do it correctly in the first place".) The correct path here, IMO, would be to simply carry the expression result (since we're using '(' expr ')' out and allow dereferencing on whatever comes out of it.




Here is a more contextual use case for my argument though:

  $rows = ($sql = new Sql)->from($table)->execute();
  // i can interact with both $sql and $rows at this point.


-ralph

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

Reply via email to