Edit report at http://bugs.php.net/bug.php?id=53697&edit=1
ID: 53697 Comment by: pablick at gmail dot com Reported by: pablick at gmail dot com Summary: "new" keyword vs. call_user_func Status: Open Type: Feature/Change Request Package: Class/Object related Operating System: Irrelevant PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: The importance of this bug is just in simplicity: If one wants to have a static method named "new", that will be creating instances (singletons or any other controlled process of instantiation), it's more convenient to have a class method named "new" in the API docs rather than having to type ClassName::getNewInstance(). Previous Comments: ------------------------------------------------------------------------ [2011-01-08 15:03:33] pablick at gmail dot com Description: ------------ When one defines a class with __callStatic() which under some circumstances accepts method name of "new", it may not be called. However, with __call(), it may be called. May be solved using call_user_func(), but that loses the nice syntax. Personally, I don't get it why "new" is parsed as T_NEW after "Base::" and not after $base->. Test script: --------------- <?php class Base { public static function __callStatic($method, $args) { if ($method == 'new') echo 'Base::new() called successfully'; } public function __call($method, $args) { if ($method == 'new') echo '$base->new() called successfully'; } } $base = Base::new(); call_user_func(array('Base', 'new'); $base = new Base; $base->new(); ?> Expected result: ---------------- Base::new() called successfully Base::new() called successfully $base->new() called successfully Actual result: -------------- Parse error: syntax error, unexpected T_NEW, expecting T_STRING or T_VARIABLE or '$' in C:\inetpub\wwwroot\test.php on line 14 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53697&edit=1