cgm225 Posted September 11, 2008 Share Posted September 11, 2008 So, I am using the following line of code... $_POST ? $comments->addComment(): null; ...so, what happens is, if there is POST data, a method is executed. However, if not, then nothing happens. However, is there a way to write this where the null does not need to be included? Link to comment https://forums.phpfreaks.com/topic/123805-conditional-statement-shorthand/ Share on other sites More sharing options...
rhodesa Posted September 11, 2008 Share Posted September 11, 2008 with the shorthand, there MUST be the TRUE and FALSE parts. If you just want the TRUE part, use an IF: if($_POST) $comments->addComment(); Link to comment https://forums.phpfreaks.com/topic/123805-conditional-statement-shorthand/#findComment-639223 Share on other sites More sharing options...
448191 Posted September 11, 2008 Share Posted September 11, 2008 Only PHP 5.3+. Then you can do '?:'. But 5.3 is still in alpha though. Link to comment https://forums.phpfreaks.com/topic/123805-conditional-statement-shorthand/#findComment-639225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.