Bug #70514 [Com]: isset(aClass::ARRAY[$a]) is mistaken for an expression

From: Date: Thu, 17 Sep 2015 01:18:02 +0000
Subject: Bug #70514 [Com]: isset(aClass::ARRAY[$a]) is mistaken for an expression
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196049@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 Comment by: feilengcui at gmail dot com Reported by: dams@php.net Summary: isset(aClass::ARRAY[$a]) is mistaken for an expression Status: Open Type: Bug Package: Class/Object related Operating System: OSX, Debian PHP Version: 7.0.0RC2 Block user comment: N Private report: N New Comment: 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" Previous Comments: ------------------------------------------------------------------------ [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 (#196049) next »