#44863 [Bgs]: isset detects an array item that var_dump does not.

From: Date: Tue, 29 Apr 2008 19:13:18 +0000
Subject: #44863 [Bgs]: isset detects an array item that var_dump does not.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124590@lists.php.net to get a copy of this message
 ID:               44863
 User updated by:  igordonin at gmail dot com
 Reported By:      igordonin at gmail dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Windows XP SP2
 PHP Version:      5.2.5
 New Comment:

Hey, I don't mean to be annoying, hope didn't get there yet, but check
this out:

Query_Repository returns string "conn_err", so it's the same as:
$Query["Try_Login"] = "conn_err";

var_dump( $Query ) results in:
array(1) { ["Try_Login"]=> string(8) "conn_err" }

There's no suck key as ["Error"] at all ...

So what you mean is that isset will recognize
$Query["Try_Login"]["Error"] as $Query["Try_Login"][0] because of the
string offset and then return true?

You may be right, that may be in fact the current behavior, but I don't
see how that can be the best behavior at all! 

I'm no expert though. So thank you very much for taking the time to
reply. I do appreciate it.


Previous Comments:
------------------------------------------------------------------------

[2008-04-29 19:03:11] colder@php.net

Yes this is expected:

non-numeric indexes are interpreted as 0 for string offsets.

so isset($string["foo"]) is equivalent to isset($string[0]) which
checks whether the string offset 0 exists, and it does, your string is
not empty.

------------------------------------------------------------------------

[2008-04-29 18:56:29] igordonin at gmail dot com

You're right!

But is this expected to return true?

if (isset($Query["Try_Login"]["Error")) {
  unset($Query["Try_Login"]["Error"]);
}

'Cause that's when I'm trying to unset
$Query["Try_Login"]["Error"] ...

------------------------------------------------------------------------

[2008-04-29 18:51:57] colder@php.net

Look: $Query is an array that contains a string at the index
"Try_Login". So $Query["Try_Login"] is a string.

You're unsetting $Query["Try_Login"]["Error"] so yes, you're trying to
unset an offset of a string.

------------------------------------------------------------------------

[2008-04-29 18:43:26] igordonin at gmail dot com

You're wrong, var_dump says:

array(1) { ["Try_Login"]=> string(8) "conn_err" } 


It's so an array!

------------------------------------------------------------------------

[2008-04-29 18:39:38] colder@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

$variable is a string and not an array. 

Your error : "Fatal error: Cannot unset string offsets" is pretty
explicit about it. 

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/44863

-- 
Edit this bug report at http://bugs.php.net/?id=44863&edit=1



Thread (8 messages)

« previous php.bugs (#124590) next »