NotionCommotion Posted July 29, 2022 Share Posted July 29, 2022 Is there any slick way of applying a method conditionally like my made up syntax below? Thanks $flag = true; $obj ->setName('bob') ->setAge(99) ->?$flag->setFoo('xxx'); //Only call setFoo if $flag is true. $obj ->setName('bob') ->setAge(99) ->?$flag->setFoo('xxx'):setBar('yyy'); //Call setFoo if $flag is true, else call setBar public function setName(string $name):self; Quote Link to comment https://forums.phpfreaks.com/topic/315106-conditionally-executing-a-method/ Share on other sites More sharing options...
requinix Posted July 29, 2022 Share Posted July 29, 2022 Not that I know of. But are you sure you want something slick? Maybe something readable would have its advantages? Quote Link to comment https://forums.phpfreaks.com/topic/315106-conditionally-executing-a-method/#findComment-1598772 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.