|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-09-16 18:39 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 18:00:02 2025 UTC |
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"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" \ --with-config-file-scan-dir=/usr/local/etc/phpng/conf.d --enable-mbstring \ --enable-tokenizer \ --disable-all make -j`sysctl -n hw.logicalcpu_max` on #master from php-src. It is working fine on Debian.