PHP Ternary operator clarification

onelis

New Member
I use the ternary operator quite often but I've not been able to find anything in the documentation about this and I've always wondered it. The following is a possible example:\[code\]echo ($something->message ? $something->message : 'no message');\[/code\]as you can see, if $something->message is correct, we return $something->message, but why write it twice? Is there a way to do something like:\[code\]echo ($something->message ? this : 'no message');\[/code\]Now I'm not well versed in programming theory, so it's possible that there is a reason that the former cannot be referenced with something like "this" but why not? Would this not stream line the use of the ternary operator? For something like my example it's pretty useless, but let's say it's \[code\]echo (function(another_function($variable)) ? function(another_function($variable)) : 'false');\[/code\]I'm unable to find any way to do this, so I'm assuming it's not possible, if I'm wrong please inform me, otherwise: why not? Why is this not possible, what's the technical reason, or is it just something that never happened? Should I be declaring it as a variable and then testing against that variable?
 
Back
Top