So I have a project that relies on Laravel 5.2 / PHP 7.0.6 and it uses Transformers to deal with API responses. In MANY places in our code we use the new php 7 coalescing (??) operators. However, since our update to php 7.0.6 we are seeing a lot of the following:
'vip_id' => $beneficiaryQdro->beneficiary->vip_id ?? ''
$beneficiaryQdro->beneficiary->vip_id ?? ''
is the same as doing:
isset($beneficiaryQdro->beneficiary->vip_id) ? $beneficiaryQdro->beneficiary->vip_id : ''
So unless the
beneficiary relationship is loaded this will always be false when doing isset and result in being ''.
There are 2 bugs fixed in PHP 7.0.6 that look like they relate to the issue you're having:
Coalescing operator on classes with overridden __get() method
Null coalescing operator and ArrayAccess
So it could be an issue with how Eloquent is handling it with its magic methods. I don't have an install under PHP 7 to confirm this though.
Looks like this was also asked here: https://laracasts.com/discuss/channels/eloquent/eloquent-relation-isset-always-return-false
It looks like it shouldn't have worked pre 7.0.6.