Re: How can I do this -- method chaining

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

 



Christoph Boget wrote:
Constructors return the object, correct?  If so, how can I do this:

class Bob {
  private $blah;
  _construct( $blah ) {
    $this->blah = $blah;
  }
  public getBlah() {
    return $this->blah;
  }
}

echo Bob( 'Hello!' )->getBlah();

When I try that, I get the message "Undefined function Bob".  I've also tried

echo new Bob( 'Hello!' )->getBlah();
echo (new Bob( 'Hello!' ))->getBlah();

Bob is a class, not a method. You could try this:

<?php
    $obj = new Bob();
    $obj->getBlah();
?>

It's not method chaining though.

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and Helpdesk software for £299pa hosted for you -
no installation, no maintenance, new features automatic and free

--
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