Bug #70514 [NEW]: isset(aClass::ARRAY[$a]) is mistaken for an expression
| From: | dams@php.net | Date: | Wed, 16 Sep 2015 18:39:32 +0000 |
| Subject: | Bug #70514 [NEW]: isset(aClass::ARRAY[$a]) is mistaken for an expression | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196044@lists.php.net to get a copy of this message | ||
From: dams
Operating system: OSX, Debian
PHP version: 7.0.0RC2
Package: Class/Object related
Bug Type: Bug
Bug description:isset(aClass::ARRAY[$a]) is mistaken for an expression
Description:
------------
Since PHP 5.6, constants may be arrays (class or global constants).
However, isset() recognize them as 'expressions' and produces a fatal
error.
if (isset(aClass::X[$a]))
if (isset(X[$a]))
On the other hand, PHP accepts :
if (isset(aClass::$X[$a]))
The behavior is in PHP 5.6 till PHP 7.0RC2 (and I tried PHP 7.1.0-dev
this afternoon).
Test script:
---------------
<?php
class W {
const X = [1 => 2, 3 => 4];
public function f() {
$a = 5;
if (isset(static::X[$a])) {
print "$a exists\n";
} else {
print "$a doesn't exists\n";
}
}
}
$x = new X;
$x->f();
Expected result:
----------------
if (isset(aClass::X[$a]))
if (isset(X[$a]))
works just like
if (isset(aClass::$X[$a]))
Actual result:
--------------
The error :
PHP Fatal error: Cannot use isset() on the result of an expression (you
can use "null !== expression" instead) in
/Users/famille/Desktop/analyze/test.php on line 9
Fatal error: Cannot use isset() on the result of an expression (you can
use "null !== expression" instead) in
/Users/famille/Desktop/analyze/test.php on line 9
--
Edit bug report at https://bugs.php.net/bug.php?id=70514&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70514&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70514&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70514&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70514&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70514&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70514&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70514&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70514&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70514&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70514&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70514&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70514&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70514&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70514&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70514&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70514&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70514&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70514&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70514&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70514&r=mysqlcfg