Re: PHP 7.1 - Address PHPSadness #28?

From: Date: Wed, 16 Sep 2015 13:26:13 +0000
Subject: Re: PHP 7.1 - Address PHPSadness #28?
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  Groups: php.internals 
Request: Send a blank email to internals+get-88239@lists.php.net to get a copy of this message
Le 16/09/2015 14:54, Rowan Collins a écrit :
The problem is that you're assigning meaning to a state that is extremely hard to work with. For instance, you can't refactor code which relies on dynamic variable existence into multiple functions, because the input parameter of the new function will always exist: ... unset($foo); refactored_code($foo); ... function refactored_code($bar) {
    if exists($bar) // oops, this is always true
    ...
}
OK, but, as I already said, an exists() construct would probably be used mostly for arrays elements and properties. Can't we accept this as a more readable alternative to array_key_exists()/property_exists() ? This is not the canonical way but it seems a lot of people already use isset() to check if an array element exists. Should we push them to array_key_exists() ? Whatever, you write in the docs, most won't do it, just because it is longer, less readable and requires to remember the args order. Providing an exists() construct has chances and would be cleaner. But this is a long term move, even if it will be quite easy to backport to PHP 5. Regards François

« previous php.internals (#88239) next »