Jump to content

Calling a method on a method


wmbetts

Recommended Posts

What's the poing of doing something like this

 

$mysqli->query("select * from table")->fetch_assoc();

 

What's the point of that? Other then to make the code look horrible?

Is there an actual benifit to it? Saving a couple lines really isn't worth it to me.

Any input on why that is better then say

 

$result = $mysql->query("select * from table");

$row = $result->fetch_array();

 

would be helpful.

Link to comment
https://forums.phpfreaks.com/topic/73972-calling-a-method-on-a-method/
Share on other sites

It's called cascading.

 

Depending on circumstance, it can be much more beneficial than to create variables that will only be used once.

 

$object->should()->be()->equal()->to(1);

as an example.

 

Another example I use frequently:

$reflect = new ReflectionClass($this);
$parent = $reflect->getParentClass->getConstructor()->getName();
$this->$parent();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.