PHP 4.4.5 call chaining?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

PHP 4.4.5 call chaining?

Post by alex.barylski »

Code: Select all

$this->_obj->someMethod()
Considering the PHP version, shouldn't that throw a fatal error? When was that functionality added?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think that's been in there a while.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Really? Huh...I could have swore it was added in PHP5...

I can't find anything on it either...I guess the changelog would be a good place to start, but frick...

I used to use firepages...when I first started with PHP and I think that was PHP3...

Hmmm...interesting cause I love that feature, but I totally thought it was part of the PHP5 new object model :P

Thanks man
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The php.exe from http://museum.php.net/win32/php-4.0.0-Win32.zip accepts

Code: Select all

<?php
class foo {
  function bar() {
    echo 'phpversion: ', phpversion(), "\n";
  }
}

class xyz {
  var $_obj;

  function xyz() {
    $this->_obj = new foo;
  }
  
  function abc() {
    $this->_obj->bar();
  }
}

$xyz = new xyz;
$xyz->abc();
and prints
X-Powered-By: PHP/4.0.0
Content-type: text/html

phpversion: 4.0.0
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Are you thinking of trying to use a return value in object context perhaps?

Code: Select all

//wont work
$foo->_getObj()->someMethod();
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

:rofl: go Hockey! Return $this, it drives everyone here nuts ;-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I like chaining. :)
Post Reply