Method chaining off constructors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Is there a reason why you can't do method chaining off of constructors?

Consider the following class:

  class bob
  {
    public function __construct()
    {
      echo 'Constructor()';
    }

    public function one()
    {
      echo '->one()';
      return $this;
    }

    public function two()
    {
      echo '->two()';
      return $this;
    }
  }

This works:

  $bob = new bob();
  $bob->one()->two();

whereas this doesn't.

  $bob = new bob()->one()->two();

Why?  I thought constructors returned the object?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux