php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1269 is_array function defines the variable?
Submitted: 1999-03-26 11:05 UTC Modified: 1999-03-26 12:17 UTC
From: arneodo at initiative dot fr Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.6 OS: NT4 SP3
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: arneodo at initiative dot fr
New email:
PHP Version: OS:

 

 [1999-03-26 11:05 UTC] arneodo at initiative dot fr
I tested this code:

if( ! isSet( $a['b'] ) ) echo "a is not set<BR>";
if( is_array( $a['b'] ) ) echo "a is an array<BR>";
if( isSet( $a['b'] ) ) echo "a is set<BR>";

and the result is:

a is not set
a is set

Conclusion:

is_array() creates the variable.

Why?
PHP Version is 3.0.6 on NT4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-03-26 12:17 UTC] zeev
is_array() doesn't create the variable, it is created before
the call to is_array(), and passed to it.  You need to understand
how PHP's automatic declaration of variables work.

In essence:
As soon as you reference a variable, it is automatically defined.
For example, if you pass a variable to is_array(), like you have
in your example, PHP checks out whether it exists, if it doesn't -
it creates it, and then it passes it over to is_array().  It has
to pass *something*, that's why the variable is automatically defined.
The implementation of is_array() has nothing to do with this
behavior - each and every function in PHP would behave in the same
way.
There aren't too many exceptions to this case, basically, only
three special functions may reference a variable without causing
it to be implicitly declared - those are unset(), isset() and empty().

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC