Update PHP to 7.0.6 can "break" your code
Attention! Be careful when upgrading PHP to version 7.0.6! In this version were fixed a few important bugs that could implicitly rely, your code or your framework code.

the
bugs.php.net/bug.php?id=62059
bugs.php.net/bug.php?id=69659
bugs.php.net/bug.php?id=71359
the
The most concise can be taken from the description of the last bug ( www.pastebucket.com/97499 in the original )
the
the
Yes.
In certain cases when you use the language construct isset() and empty () will not used call magic method __isset() if present in the class, but instead immediately called __get() and the decision was made on the basis that he will return.
This has now been fixed. It is hoped that in all cases, use isset() or empty() on the "magical" properties or "magic" keys of the array object ArrayAccess will first be called __isset().
the
What if your class has a method __get () but no method __isset(), your code will 'break'. Now in all such cases, isset() will always return false, but empty() === true
the
I would prefer to restore to 7.0.5 and then gently refactor code. It is unlikely you have many places where there are __get () but not __isset(). Subsequently, it would be nice to add to your code analyzer the appropriate rule, and to ban the toxic commit this code.
Article based on information from habrahabr.ru

the
What bugs have been fixed?
bugs.php.net/bug.php?id=62059
bugs.php.net/bug.php?id=69659
bugs.php.net/bug.php?id=71359
the
example:
The most concise can be taken from the description of the last bug ( www.pastebucket.com/97499 in the original )
the
class Test
{
protected $attributes = [
'attribute1' => 'value1',
];
public function __get($name)
{
print "GET\n";
if (array_key_exists($name, $this->attributes)) {
return $this- > attributes[$name];
}
trigger_error("Property $name does not exist");
return null;
}
public function __isset($name)
{
print "ISSET\n";
return array_key_exists($name, $this->attributes);
}
}
$obj = new Test();
var_dump($obj->attribute1 ?? 'default');
//GET
//string(6) "value1"
var_dump($obj->attribute2 ?? 'default');
//GET
//PHP Notice: Property attribute2 does not exist in /var/www/html/test.php on line 23
//string(7) "default"
the
And simple?
Yes.
In certain cases when you use the language construct isset() and empty () will not used call magic method __isset() if present in the class, but instead immediately called __get() and the decision was made on the basis that he will return.
This has now been fixed. It is hoped that in all cases, use isset() or empty() on the "magical" properties or "magic" keys of the array object ArrayAccess will first be called __isset().
the
Than it threatens me personally?
What if your class has a method __get () but no method __isset(), your code will 'break'. Now in all such cases, isset() will always return false, but empty() === true
the
What to do?
I would prefer to restore to 7.0.5 and then gently refactor code. It is unlikely you have many places where there are __get () but not __isset(). Subsequently, it would be nice to add to your code analyzer the appropriate rule, and to ban the toxic commit this code.
Comments
Post a Comment