The arguments to the ternary operator, like any other operator, must be expressions. require_once
is PHP syntax, it's not a function, so it can't be used within an expression. So you should use the ternary operator in the argument to require_once
, which is an expression.
require_once (getStatus() ? 'a.php' : 'b.php');
For your extra request, you can do it with the ternary operator, but the result is not pretty, and IMHO harder to understand than the original:
call_user_func_array('setcookie',
websiteIsLive() ?
array("token", x, 0, '/', $_SERVER['HTTP_HOST'], true) :
array("token", y, 0, '/'));