php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65652 isset alternative
Submitted: 2013-09-11 12:34 UTC Modified: 2013-09-11 22:23 UTC
From: kozak at eurosat dot cz Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.5.3 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kozak at eurosat dot cz
New email:
PHP Version: OS:

 

 [2013-09-11 12:34 UTC] kozak at eurosat dot cz
Description:
------------
At the moment isset call return true only when variable is set and it is not 
null.

But there is no way (or I do not find it so far), how to just test variable for 
existance. So it will be perfect if there will be some other call (for eg: exist) 
or some parametr how to get this behaviour
More in example. 

Test script:
---------------
$a = null;
$testOnlyExistence = true;

echo isset($b); // prints false;
echo isset($a); // prints false;
echo isset($a, $testOnlyExistence); // prints true;
echo isset($b, $testOnlyExistence); // prints false;
// or
echo exist($a); // prints true;
echo exist($b); // prints false;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-11 17:45 UTC] anon at anon dot anon
echo array_key_exists('b', get_defined_vars()) ? "exists" : "doesn't exist";
 [2013-09-11 20:14 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2013-09-11 20:14 UTC] aharvey@php.net
It's an unusual enough need that I think the get_defined_vars() solution posted 
in the previous comment is good enough.
 [2013-09-11 22:23 UTC] kozak at eurosat dot cz
aharvey not it is not. Because array_key_exists is slow.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 15:01:30 2024 UTC