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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 02 10:01:28 2025 UTC