Bug #70514 [Opn->Fbk]: isset(aClass::ARRAY[$a]) is mistaken for an expression

From: Date: Sat, 19 Sep 2015 01:24:36 +0000
Subject: Bug #70514 [Opn->Fbk]: isset(aClass::ARRAY[$a]) is mistaken for an expression
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196081@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70514&edit=1 ID: 70514 Updated by: bwoebi@php.net Reported by: dams@php.net Summary: isset(aClass::ARRAY[$a]) is mistaken for an expression -Status: Open +Status: Feedback Type: Bug Package: Class/Object related Operating System: OSX, Debian PHP Version: 7.0.0RC2 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2015-09-18 17:47:44] 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-18 04:08:06] laruence@php.net did I misunderstand something here? https://3v4l.org/upQIg it seems works fine with php7 ------------------------------------------------------------------------ [2015-09-17 09:15:39] dams@php.net OK, I made it to work on Debian with 7.1.0-dev. Recompiled on osx too, but still doesn't work. ------------------------------------------------------------------------ [2015-09-17 01:18:01] feilengcui at gmail dot com hello,I just test your code for 7.0RC1 and 7.0RC2, and I find that if(isset(aClass::X[$a])) if(isset(X[$a])) are both OK and output "5 doesn't exists" but for if(isset(aClass::$X[$a])) it reports an error "Fatal error: Uncaught EngineException: Access to undeclared static property: W::$X" ------------------------------------------------------------------------ [2015-09-16 18:39:31] dams@php.net 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 this bug report at https://bugs.php.net/bug.php?id=70514&edit=1

« previous php.bugs (#196081) next »