The problem here is that isset()
is not a real function but a language construct, which requires its arguments to be variables, or it issues a syntax error.
See also the manual entry: http://php.net/manual/en/function.isset.php
Anyway, as also @deceze said, you probably do not want to use isset()
here, since it is used to check if a variable exists.
In this case, you could use empty()
, so instead of writing
$openMonday = rtrim(chunk_split($result['opening_hours']['periods'][1]['open']['time'], 2, ':'), ':');
$business->openingTimes['monday'] = isset($openMonday) ? $result['opening_hours']['periods'][1]['open']['time'] : '';
you could do
$openMonday = rtrim(chunk_split($result['opening_hours']['periods'][1]['open']['time'], 2, ':'), ':');
$business->openingTimes['monday'] = !empty($openMonday) ? $result['opening_hours']['periods'][1]['open']['time'] : '';
And you should not worry to make it a one-liner at any cost! Create a function instead, and then call it when needed... But if you really still want to do it inline, then you could do
$business->openingTimes['monday'] = !empty(rtrim(chunk_split($result['opening_hours']['periods'][1]['open']['time'], 2, ':'), ':')) ? $result['opening_hours']['periods'][1]['open']['time'] : '';
just remember that the above requires at least PHP 5.5!
And finally, the row above could just be written as
$business->openingTimes['monday'] = !rtrim(chunk_split($result['opening_hours']['periods'][1]['open']['time'], 2, ':'), ':') ? $result['opening_hours']['periods'][1]['open']['time'] : '';
without any need for isset()
nor empty()