php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21490 isset in an array
Submitted: 2003-01-07 07:53 UTC Modified: 2003-01-07 08:06 UTC
From: mickael dot bailly at free dot fr Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.0 OS: Linux
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: mickael dot bailly at free dot fr
New email:
PHP Version: OS:

 

 [2003-01-07 07:53 UTC] mickael dot bailly at free dot fr
Don't know if it's a bug or a feature... :)

$test = array ('a' => 'coooool','b' => $ddfdfdf);
if ( isset($test['b']) ) {
	echo "OOOK ! \n";
}

echoes nothing, and

$test = array ('a' => 'coooool','b' => "$ddfdfdf");
if ( isset($test['b']) ) {
	echo "OOOK ! \n";
}
echoes OOOK

Is this normal ?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-07 07:58 UTC] nicos@php.net
Yes it $ddfdfdf is empty, isset will return FALSE.

According to the following script :

<?php

$test = array ('a' => 'coooool','b' => "$tests");
if (isset($test['b']) ) {
echo "OK 1! \n";
}

$test = array ('a' => 'coooool','b' => $tests);
if ( isset($test['b']) ) {
echo "OK 2! \n";
}

$tests = "lol";

$test = array ('a' => 'coooool','b' => $tests);
if ( isset($test['b']) ) {
echo "OK 3! \n";
}

?>

That returns:

OK 1!
OK 3!

If you set an element of an array to a variable that is empty, isset will definatly return FALSE.

Excepted behaviour.
 [2003-01-07 08:06 UTC] nicos@php.net
Note:

$test = ""; sets the variable test to an empty string. 
So isset() will return TRUE. Since you're passing "$var" and $var is empty, it will be set to an empty string. 

That explains why it returns TRUE with "$var" and not with only $var.

Thank you for your report.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 16:01:37 2025 UTC