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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to