wmbetts Posted October 19, 2007 Share Posted October 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73972-calling-a-method-on-a-method/ Share on other sites More sharing options...
Daniel0 Posted October 22, 2007 Share Posted October 22, 2007 The two snippets you posted do the exact same thing. The point in doing the first would be to decrease the amount of code in your script. Quote Link to comment https://forums.phpfreaks.com/topic/73972-calling-a-method-on-a-method/#findComment-375457 Share on other sites More sharing options...
Jenk Posted October 22, 2007 Share Posted October 22, 2007 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(); Quote Link to comment https://forums.phpfreaks.com/topic/73972-calling-a-method-on-a-method/#findComment-375518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.