You cannot do what you ask; but you can "cheat" using the fact that in PHP you may have a function with the same name as the class; these names will not conflict.
So, if you declared a class like this:
class Test { public function __construct($param) { $this->_var = $param; } public function myMethod() { return $this->_var * 2; } protected $_var; }
Then you can declare a function that returns an instance of this class and has exactly the same name as the class:
function Test($param) { return new Test($param); }
And now it becomes possible to use a single line, as you requested - the only thing you call the function, that is, do not use new:
$a = Test(10)->myMethod(); var_dump($a);
And it works: here, I get:
int 20
as a conclusion.
And, better, you can add phpdoc to your function:
function Test($param) { return new Test($param); }
That way, you'll even have hints in your IDE - at least with Eclipse PDT 2.x; see screenshot:

Edit 2010-11-30: Just for information, a new RFC was introduced a few days ago, which suggests adding this function to one of the future versions of PHP.
See: Requesting Comments: Instance and Method Call / Property Access
So maybe something like this will be possible in PHP 5.4 or another future version:
(new foo())->bar() (new $foo())->bar (new $bar->y)->x (new foo)[0]
Pascal MARTIN Sep 09 '09 at 22:44 2009-09-09 22:44
source share