|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70514 isset(aClass::ARRAY[$a]) is mistaken for an expression
Submitted: 2015-09-16 18:39 UTC Modified: 2015-10-11 04:22 UTC
From: Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 7.0.0RC2 OS: OSX, Debian
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-09-16 18:39 UTC]
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:

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;

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-17 01:18 UTC] feilengcui at gmail dot com
hello,I just test your code for 7.0RC1 and 7.0RC2, and I find that 
are both OK and output "5 doesn't exists"

but for 
it reports an error
    "Fatal error: Uncaught EngineException: Access to undeclared static property: W::$X"
 [2015-09-17 09:15 UTC]
OK, I made it to work on Debian with 7.1.0-dev. 

Recompiled on osx too, but still doesn't work.
 [2015-09-18 04:08 UTC]
did I misunderstand something here?

it seems works fine with php7
 [2015-09-18 17:47 UTC] iletisim at ilkerozcan dot com dot tr
Works on ubuntu but does not work on OsX. It may be due to the bison version.
 [2015-09-19 01:24 UTC]
-Status: Open +Status: Feedback
 [2015-09-19 01:24 UTC]
Works for me on OS X with PHP 7...

Just on PHP 5.6, isset() did not support constant arrays at all. I just had forgotten to take care of that special case back then.

isset(aClass::X) still does not work with PHP 7, but aClass::X[$a] (or static::X[$a]) definitely should work there.
 [2015-09-22 15:16 UTC]
I tried with bison 2.7 and 3.0.4, with the same result. 

I use this compilation sequence : 
make clean

./buildconf --force
env YACC=`brew --prefix bison27`/bin/bison 
./configure \
    --prefix="/usr/local/opt/phpng" \
    --with-config-file-path="/usr/local/etc/phpng" \
    --enable-mbstring \
    --enable-tokenizer \
make -j`sysctl -n hw.logicalcpu_max`

on #master from php-src. 

It is working fine on Debian.
 [2015-09-28 09:10 UTC]
I confirm the situation from bwoebi : 

aClass::X[$a] (or static::X[$a]) work fine.

isset(aClass::X) still does not work. 

The revision is 250938e2d35fc54161a18167b7901c5e3b574371. 
I'll keep testing until the 2nd instruction is ok. The rest is good to for, AFAIK
 [2015-10-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2016-05-18 15:31 UTC] phansys at gmail dot com
This issue is present in 5.6.21 version too.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 04:01:33 2024 UTC