-
Syntax Woes
Okay, so I can't do this?
PHP Code:
<?php
class A { public function A() {} public function B() {} }
new A()->B();
?>
How can I do this in one line?
Also, what the difference between using __construct, and a function which has the same name as the class?
-
Re: Syntax Woes
You can't do it in one line. First you have to create the object. Then after the object is created, then you may reference other methods contained within.
As for your second questions...it was just asked recent in this very same forum.
-
Re: Syntax Woes
You can achieve something similar with a static constructor:
PHP Code:
class A {
public static create()
{
return new A();
}
public function foo()
{
doSomething();
return $this;
}
public function bar()
{
$result = doOtherSomething();
return $result;
}
}
$barResult = A::create()->foo()->bar();