php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44587 Problems whene asking if a key of an array isset, and the variable is not array
Submitted: 2008-04-01 10:48 UTC Modified: 2008-04-02 00:03 UTC
From: francesco at facconi dot eu Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.5 OS: Linux 2.6.18-6-686
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 - 36 = ?
Subscribe to this entry?

 
 [2008-04-01 10:48 UTC] francesco at facconi dot eu
Description:
------------
I was evaluating a variable with isset. I don't know what kind of variable it is before evaluating.

If I do a isset of a key of an array, and the variable is NOT an array, I receive a true response. I think this is not a good result.

Reproduce code:
---------------
function verify($var) {
  if (isset($var['key'])) {
    echo "OK";
  } else {
    echo "NO";
  }
  return;
}

verify ('asdfghjkl');
verify (array('key'=>'1', 'option'=>'2');
verify (array('action'=>'1', 'option'=>'2');

Expected result:
----------------
## verify ('asdfghjkl');
NO

## verify (array('key'=>'1', 'option'=>'2');
OK

## verify (array('action'=>'1', 'option'=>'2');
NO

Actual result:
--------------
## verify ('asdfghjkl');
OK

## verify (array('key'=>'1', 'option'=>'2');
OK

## verify (array('action'=>'1', 'option'=>'2');
NO

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-02 00:03 UTC] felipe@php.net
This is expected, the string key is converted to integer.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 22:01:28 2024 UTC