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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 09:01:34 2025 UTC