php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45724 correct "new Object()->method()"
Submitted: 2008-08-05 12:31 UTC Modified: 2010-11-23 10:33 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bastard_man at hotmail dot co dot uk Assigned:
Status: Duplicate Package: *General Issues
PHP Version: 5.3CVS-2008-08-05 (CVS) OS: XP/Ubuntu
Private report: No CVE-ID: None
 [2008-08-05 12:31 UTC] bastard_man at hotmail dot co dot uk
Description:
------------
Hello,
can you help me with a feature change in PHP?
in java this code works well

AClass object = new AClass().aMethod();

in php it doesnt.

It is possible to correct this so the syntax is valid?

Reproduce code:
---------------
class AClass
{
	public function __construct()
		{echo("a"); /* return $this; ???? */ }
	public function method1()
		{echo("b"); return $this;}
	public function method2()
		{echo("c"); return $this;}
	public static main()
		{$obj = new TestPhp()->method1()->method2();}
}
AClass::main();

Expected result:
----------------
abc

Actual result:
--------------
(Fatal Error)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-23 10:33 UTC] aharvey@php.net
-Status: Open +Status: Duplicate -Package: Feature/Change Request +Package: *General Issues
 [2010-11-23 10:33 UTC] aharvey@php.net
Duplicate of request #34502.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC