Reputation: 5006
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.
Upvotes: 0
Views: 43
Reputation: 3005
Add your conditions in a parenthesis and type cast Boolean to String.
return 'autoOpenPopup: '.(string) (!empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL);
Upvotes: 1
Reputation: 1097
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.'';
Upvotes: 1