PHP Object Oriented Programming Course - Question

Hello, im taking the course in the title, very good so far, i have a question, nothing with oop, but never seen a sentence like this before:
strlen($spass) < self::MINCHAR ? false : true

I understand that im getting the string length of the $spass variable, then i compare if $spass is less than (8 chars, in this case the value of the constant MINCHAR), then never seen this part ? false : true. I understand that it returns true or false, but this can be use in any comparisson? where i can find the documentation about the uses of the ? false : true, ? can i put true before false?


That’s the ternary operator.

$test ? $a : $b

This statement will return $a if $test is true and $b otherwise. So in your example, the expression will return false if $spass has less than 8 characters, and true otherwise.

Here’s a video lesson on Envato Tuts+.

Awesome, thanks for your help, i was trying to get help looking for the syntax ? false : true on google, the term “ternary operator” solved. Thanks for the video im looking it right now.


1 Like