php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76135 isset should support expressions like empty does
Submitted: 2018-03-22 05:11 UTC Modified: 2021-11-15 16:36 UTC
From: faith dot morante at gmail dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.1.15 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: faith dot morante at gmail dot com
New email:
PHP Version: OS:

 

 [2018-03-22 05:11 UTC] faith dot morante at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.isset
---


Getting this error:
Cannot use isset() on the result of an expression (you can use "null !== expression" instead) on line number 3

When explicitly passing a data in isset. Passing a variable with the same data works,though.

Test script:
---------------
var_dump(isset(null));

Expected result:
----------------
false

Actual result:
--------------
Cannot use isset() on the result of an expression (you can use "null !== expression" instead) on line number 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-22 05:17 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-03-22 05:17 UTC] requinix@php.net
Don't use isset on the result of an expression.

If you're trying to say that the documentation does not mention this, it does:
> Warning: isset() only works with variables as passing anything else will result in a parse error.
 [2018-03-22 05:21 UTC] faith dot morante at gmail dot com
I see, thanks!
But how come the empty function works with non-variables?
 [2018-03-22 05:25 UTC] requinix@php.net
-Summary: Issue with Isset +Summary: isset should support expressions like empty does -Status: Not a bug +Status: Open -Type: Documentation Problem +Type: Feature/Change Request -Package: Documentation problem +Package: Scripting Engine problem
 [2018-03-22 05:25 UTC] requinix@php.net
Why does any function work the way it does?

I don't know of any reason why isset shouldn't work on expressions. I don't like inconsistencies. Let's make this a feature request instead.
 [2021-11-15 15:51 UTC] cmb@php.net
> I don't know of any reason why isset shouldn't work on
> expressions.

Well, why would that be particularly useful?  isset() checks that
some value is set (not IS_UNDEF) and is not null.  An expression
never evaluates to IS_UNDEF, so isset() on an expression would be
equivalent to check for !== null.  If one wanted the benefits of
checking multiple expressions in one go, they could define their
own function for that.
 [2021-11-15 16:36 UTC] requinix@php.net
> Well, why would that be particularly useful?  isset() checks that some value is
> set (not IS_UNDEF) and is not null.  An expression never evaluates to IS_UNDEF,
> so isset() on an expression would be equivalent to check for !== null.

What about empty? It's equivalent to IS_UNDEF || ==false, but it allows expressions. If isset should not allow expressions because they're never undefined and you can !==null instead then empty should not either because they're never undefined and you can ==false (or !expr) instead.

I agree it does feel weird to call isset on an expression, but I don't know if there's an objective reason to not allow it. (That said, IMO this is still a request and not a bug.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 05 07:01:30 2024 UTC