|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-02-03 02:31 UTC] rasmus@php.net
[2008-02-03 02:45 UTC] giorgio dot liscio at email dot it
[2008-02-04 08:30 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
Description: ------------ Hello, i'm asking for a feature change in PHP in java this code works nice MyClass object = new MyClass().someMethod(); in php not too. It is possible make working this syntax? thank you [for creating my favourite language] :) Reproduce code: --------------- <?php /* JAVA CODE: class TestPhp { public TestPhp() {System.out.print("Construct ");} public TestPhp method1() {System.out.print("Method1 "); return this;} public TestPhp method2() {System.out.print("Method2 "); return this;} public static void main(String []args) {TestPhp obj = new TestPhp().method1().method1();} } */ class TestPhp { public function __construct() {echo("Construct ");} public function method1() {echo("Method1 "); return $this;} public function method2() {echo("Method2 "); return $this;} public static main() {$obj = new TestPhp()->method1()->method2();} } TestPhp::main(); ?> Expected result: ---------------- Construct Method1 Method2 Actual result: -------------- (Fatal Error)