php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1535 isset() with trinary operator implicitly declares array variable
Submitted: 1999-06-14 02:26 UTC Modified: 1999-06-20 21:05 UTC
From: walton at nordicdms dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.7 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: walton at nordicdms dot com
New email:
PHP Version: OS:

 

 [1999-06-14 02:26 UTC] walton at nordicdms dot com
In bug #1269, Zeev says:

> 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().

I seem to have found an instance where isset() will implicitly declare a variable.  I think.  Maybe it's the trinary operator doing it.  Either way, I don't think it should be happening.

  # php -q
  <?
  echo isset($x[0]);
  0
  $x[0] = isset($x[0]) ? 'y' : 'n';
  echo $x[0];
  y
  echo isset($x[0]);
  1

Obviously, $x[0] should end up being created when a value is assigned to it, but that should not happen until after the expression is evaluated to determine what value to assign.  A similar script that does not use arrays works as expected.  I spent an hour trying to figure out why my script wasn't working right when $x[0] was not set, since the code appears correct on inspection.  It just doesn't behave the same way it does with a simple scalar variable.

Dave


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-20 21:05 UTC] jim at cvs dot php dot net
You're making order of execution assumptions that are
not guaranteed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 05:01:31 2024 UTC