ID:               44026
 Updated by:       [EMAIL PROTECTED]
 Reported By:      giorgio dot liscio at email dot it
-Status:           Analyzed
+Status:           Wont fix
 Bug Type:         Feature/Change Request
 Operating System: winxpsp2 / Apache 2
 PHP Version:      5.2.5
 New Comment:

No need, if you really want this,m you can use a factory pattern:

$res = A::create()->method1()->method2();




Previous Comments:
------------------------------------------------------------------------

[2008-02-03 02:45:22] giorgio dot liscio at email dot it

don't know... i think it can be useful in some cases... for example:

$a = new A();
$b = new B();
$c = new C();
$d = new D();
$e = new E();
$f = new F();
$g = new G();
$h = new H();
$i = new I();
// ... a lot of codelines that can be removed

$obj->add(
$a->method1()->method2()->method3(),
$b->method1()->method2()->method3(),
$c->method1()->method2()->method3(),
$d->method1()->method2()->method3(),
...
);

instead, with this feature, the code can be a lot shorter

$obj->add(
new A()->method1()->method2()->method3(),
new B()->method1()->method2()->method3(),
new C()->method1()->method2()->method3(),
new D()->method1()->method2()->method3(),
...
);

it is not indispensable, but i can, and my applications too, really
appreciate this feature, instance objects and use methods in the same
row

------------------------------------------------------------------------

[2008-02-03 02:31:31] [EMAIL PROTECTED]

As far as I am concerned this just makes the code harder to read.  What
do you actually gain vs. just doing:

  $obj = new TestPhp();
  $obj->method1()->method2();

And it gets really confusing if the functions don't return $this since
then $obj wouldn't necessarily be the actual instantiated object.  I
guess we can leave it as a feature request, but unless some other
developer takes a liking to this, I doubt it will happen.

------------------------------------------------------------------------

[2008-02-03 01:15:42] giorgio dot liscio at email dot it

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)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44026&edit=1

Reply via email to