|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-11-01 13:44 UTC] cf0hay at gmail dot com
Description:
------------
A crash occurs when *all* of the following conditions met:
* there is a "use const" statement in a namespace
* a (static) function references that constant
* that constant haven't been defined
* the referencing function is called
* opcache is enabled
* FPM is the environmet
* php 5.6 is the version
- if there is no "use const", the old behavior works, as in it will use the constant from global namespace
- if nothing referneces the constant, it will not crash
- if the constant is defined before use, crash will not occur
- if the referncing function is not called, crash will not occur
- if opcache is *disabled*, crash not occurs (the code issues notices)
- if run from CLI, crash not occurs (the code issues notices)
- afaik php < 5.6 doesn't have this feature, and php 7.0 RC 6 is not affected, as it creates a fatal error instead, so only php 5.6 is affected
Test script:
---------------
<?php
namespace test {
use const nonexistent;
class test {
static function run(){
var_dump(nonexistent);
}
}
}
namespace {
test\test::run();
}
Expected result:
----------------
PHP Notice: Use of undefined constant nonexistent - assumed 'nonexistent'
Actual result:
--------------
Segmentation fault
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 11:00:02 2025 UTC |
actually, this is not a opcache issue, please verify the following fix: diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5ff1b04..39d6ed6 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -545,6 +545,13 @@ int zend_add_const_name_literal(zend_op_array *op_array, const zval *zv, int unq tmp_literal = zend_add_literal(CG(active_op_array), &c TSRMLS_CC); CALCULATE_LITERAL_HASH(tmp_literal); + if (unqualified && !ns_len) { + /* we should ensure there are five literals */ + ZVAL_STRINGL(&c, STR_EMPTY_ALLOC(), 0, 0); + tmp_literal = zend_add_literal(CG(active_op_array), &c TSRMLS_CC); + tmp_literal = zend_add_literal(CG(active_op_array), &c TSRMLS_CC); + } + return ret; } /* }}} */ thanksto prove this is not an opcache issue, please see the following test script: <?php namespace test { use const nonexistent; class test { static function run(){ var_dump(nonexistent); existent; } } } namespace { define("test\\existent", "bug!", 1); test\test::run(); } which will result "bug!"