Wired constant expression syntax and bug

From: Date: Mon, 30 Jun 2014 19:06:06 +0000
Subject: Wired constant expression syntax and bug
Groups: php.internals 
Request: Send a blank email to internals+get-75149@lists.php.net to get a copy of this message
Hi Bob, I'm wondered why you introduced this wired syntax in PHP-5.6. class FooBar { const bar = ["bar" => 3]["bar"]; } It wasn't a part of RFC, it wasn't covered by tests, and it actually doesn't make a lot of sense. May be it's better to remove it? Also I found a constant expression related bug, that leads to unpredictable crashes from time to time. Previously we had IS_CONSTANT_ARRAY that was handled in a special way. When you replaced it with IS_ARRAY, you missed this handling, and I missed it as well when reviewed your patch. Now IS_ARRAY constants might be incompletely copied from OPCache shared memory and modified (incremented/decremented reference counter) directly in SHM. Such modifications occur in simultaneously running processes and this finally leads to crash on some race condition. It's possible to emulate the problem running the following script with opcache.protect_memory=1 <?php function foo($query = NULL, array $exclude = array('q')) {} foo(); ?> I propose a simple fix: https://gist.github.com/dstogov/b73884e252b376957ebc Please review and apply if agree. Thanks. Dmitry.

« previous php.internals (#75149) next »