Commit:    73f13f439b3e10cca9b17e7f15c06e7fd11eb6c9
Author:    Dmitry Stogov <dmi...@zend.com>         Tue, 10 Dec 2013 17:04:17 
+0400
Parents:   1e161a9c0fc215344998674401122f62077c47af
Branches:  PHP-5.6 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=73f13f439b3e10cca9b17e7f15c06e7fd11eb6c9

Log:
Fixed bug #66251 (Constants get statically bound at compile time when Optimized)

Bugs:
https://bugs.php.net/66251

Changed paths:
  M  ext/opcache/Optimizer/pass1_5.c
  A  ext/opcache/tests/bug66251.phpt


Diff:
diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c
index bd8af47..f173c3f 100644
--- a/ext/opcache/Optimizer/pass1_5.c
+++ b/ext/opcache/Optimizer/pass1_5.c
@@ -321,6 +321,27 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
                        break;
 
                case ZEND_DO_FCALL:
+                       /* define("name", scalar); */
+                       if (collect_constants &&
+                           opline->extended_value == 2 &&
+                           ZEND_OP1_TYPE(opline) == IS_CONST &&
+                           Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
+                           Z_STRLEN(ZEND_OP1_LITERAL(opline)) == 
sizeof("define")-1 &&
+                           
zend_binary_strcasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), 
Z_STRLEN(ZEND_OP1_LITERAL(opline)), "define", sizeof("define")-1) == 0 &&
+                           (opline-1)->opcode == ZEND_SEND_VAL &&
+                           ZEND_OP1_TYPE(opline-1) == IS_CONST &&
+                           (Z_TYPE(ZEND_OP1_LITERAL(opline-1)) <= IS_BOOL ||
+                            Z_TYPE(ZEND_OP1_LITERAL(opline-1)) == IS_STRING) &&
+                           (opline-2)->opcode == ZEND_SEND_VAL &&
+                           ZEND_OP1_TYPE(opline-2) == IS_CONST &&
+                           Z_TYPE(ZEND_OP1_LITERAL(opline-2)) == IS_STRING) {
+                               zend_optimizer_collect_constant(constants, 
&ZEND_OP1_LITERAL(opline-2), &ZEND_OP1_LITERAL(opline-1));
+                               break;
+                       } else {
+                               /* don't colllect constants after any other 
function call */
+                               collect_constants = 0;
+                       }
+
                        /* pre-evaluate constant functions:
                           defined(x)
                           constant(x)
@@ -428,25 +449,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
                                                MAKE_NOP(opline);
                                        }
                                }
-                               break;
-                       }
-                       
-                       /* define("name", scalar); */
-                       if (collect_constants &&
-                           opline->extended_value == 2 &&
-                           ZEND_OP1_TYPE(opline) == IS_CONST &&
-                           Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
-                           Z_STRLEN(ZEND_OP1_LITERAL(opline)) == 
sizeof("define")-1 &&
-                           
zend_binary_strcasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), 
Z_STRLEN(ZEND_OP1_LITERAL(opline)), "define", sizeof("define")-1) == 0 &&
-                           (opline-1)->opcode == ZEND_SEND_VAL &&
-                           ZEND_OP1_TYPE(opline-1) == IS_CONST &&
-                           (Z_TYPE(ZEND_OP1_LITERAL(opline-1)) <= IS_BOOL ||
-                            Z_TYPE(ZEND_OP1_LITERAL(opline-1)) == IS_STRING) &&
-                           (opline-2)->opcode == ZEND_SEND_VAL &&
-                           ZEND_OP1_TYPE(opline-2) == IS_CONST &&
-                           Z_TYPE(ZEND_OP1_LITERAL(opline-2)) == IS_STRING) {
-                               zend_optimizer_collect_constant(constants, 
&ZEND_OP1_LITERAL(opline-2), &ZEND_OP1_LITERAL(opline-1));
-                       }
+                       }                       
                        break;
 #if ZEND_EXTENSION_API_NO > PHP_5_2_X_API_NO
                case ZEND_DECLARE_CONST:
@@ -487,6 +490,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
                case ZEND_FE_RESET:
                case ZEND_FE_FETCH:
                case ZEND_NEW:
+               case ZEND_DO_FCALL_BY_NAME:
 #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
                case ZEND_JMP_SET:
 #endif
diff --git a/ext/opcache/tests/bug66251.phpt b/ext/opcache/tests/bug66251.phpt
new file mode 100644
index 0000000..23a5165
--- /dev/null
+++ b/ext/opcache/tests/bug66251.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #66251 (Constants get statically bound at compile time when Optimized)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php if (!extension_loaded('Zend OPcache') || php_sapi_name() != "cli") 
die("skip CLI only"); ?>
+--FILE--
+<?php
+printf ("A=%s\n", getA());
+const A="hello";
+function getA() {return A;}
+?>
+--EXPECTF--
+Notice: Use of undefined constant A - assumed 'A' in %sbug66251.php on line 4
+A=A


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to