Question

Can I do this? (I can't test it at the moment to see for myself)

public function overSimplifiedTernaryTest($condition = false) {
    return ($condition) ? 'someString' : 'someOtherString';
}
Was it helpful?

Solution

It works and next time you can use ideone.com to test your code instead of asking question.

Your code : http://ideone.com/2oHkF

You can also refer to this question for additionnal online tool to test your code.

OTHER TIPS

This is working.

Example:

class CClass
{
    public function overSimplifiedTernaryTest($condition = false)
    {
        return ($condition) ? 'someString' : 'someOtherString';
    }
}

$x = new CClass();
echo $x->overSimplifiedTernaryTest(false) . 
     '\r\n' . 
     $x->overSimplifiedTernaryTest(true);
delete $x;

Yes, you can do that.

Example

The ternary operator will return one value, which is what you then return from the function. This is why what you're trying to do will be no problem. It'll also work in other languages, you could do this in Javascript also for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top