|
-
August 12th, 2009, 04:45 PM
#1
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?
-
August 12th, 2009, 06:04 PM
#2
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
August 18th, 2009, 07:20 PM
#3
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();
All consequences are eternal in some way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|