Search code examples
javascriptphpquote

Php nesting code with quotes


I have some chunks of code I have trouble nesting:

return 'autoOpenPopup: '.!empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL.'';

this prints false (result of autoOpenPopup var) instead of:

autoOpenPopup: false

It works if I do this:

$t = !empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL;

return 'autoOpenPopup: '.$t.'';

But I wanted to nest this is possible.


Solution

  • Try to wrap the ternary in parenthesis '(...)';

    return 'autoOpenPopup: '.( !empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) ) . PHP_EOL.'';