xpuc7o xpuc7o - 1 year ago 94
PHP Question

Why __isset() is not triggered in Laravel Model?

I have a Laravel project with this code:

$names = isset($user->party->personName->first_name) ? $user->party->personName->first_name . ' ' . $user->party->personName->last_name : null;

$role = $user->userRole->role->name ?? null

On the dev server this is working. On Homestead
are always
. As I know
should trigger
method in the
class but id does not.

Laravel version - 5.2.31

PHP on dev server - 7.0.2

PHP on Homestead - 7.0.8-2+deb.sury.org~xenial+1

Is this because the difference of the PHP versions or there is some setting?

Answer Source

The behaviour changed in PHP 7.0.6. You can reproduce a basic example using the following:

class Foo {
  public function __isset($arg) {
    echo '__isset called', PHP_EOL;

$foo = new Foo;

echo 'Basic:', PHP_EOL;

echo 'Deep:', PHP_EOL;

Before 7.0.6, the __isset method was only called for the top-level property, whereas now it's called for the deeper, child property as well.

See https://3v4l.org/D389q for the different results.

It looks to stem back to a fix applied for this bug: https://bugs.php.net/bug.php?id=69659

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download