Re: PHP 7.1 - Address PHPSadness #28?

From: Date: Thu, 17 Sep 2015 13:46:50 +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-88284@lists.php.net to get a copy of this message
Terry Cullen wrote on 17/09/2015 14:09:
​I agree that there is already ways around this issue, but I agree with Bob that there is a hole that exists() would fill. I my world where PHP is the glue between JSON requests and database queries, ​ exists() would be a function I'd use way more the array_key_exists(), property_exists(), isset() and empty(). Further, in some scenarios exists($foo->bar) would replace isset($foo) && is_object($foo) && property_exists($foo, 'bar').
Yes, I've proposed elsewhere in this thread an exists() function (maybe under a different name) that is just syntax sugar for array_key_exists/property_exists, and raises an error if used with a bare variable. This, it turns out, is exactly what Perl has: http://perldoc.perl.org/functions/exists.html So you'd write exists($foo->bar), and the compiler would basically turn that into property_exists('bar', $foo) with appropriate suppression of notices in the same way isset() and empty() have. There is still the problem that as this would be a language construct not a real function, there would be no way to polyfill it for older versions, so you couldn't use it until your code had a minimum version requirement of 7.1. A PECL extension *might* be able to backport it to older versions of PHP, but I doubt it would gain much adoption. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#88284) next »