Commit:    e1125a6a894a8b005aaea6b8ce2e0ea6bf39e483
Author:    Igor Wiedler <i...@wiedler.ch>         Tue, 23 Jul 2013 21:08:49 
+0200
Parents:   5dd41627bed892e76492ae3945e3b0d9cac21019
Branches:  PHP-5.6 master

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

Log:
Correctly distinguish between functions and constants

So far 'use function' applied to both constants and functions. This
patch correctly separates the two.

Changed paths:
  A  Zend/tests/use_function/ignore_constants.phpt
  M  Zend/zend_compile.c
  M  Zend/zend_compile.h


Diff:
diff --git a/Zend/tests/use_function/ignore_constants.phpt 
b/Zend/tests/use_function/ignore_constants.phpt
new file mode 100644
index 0000000..c50ff73
--- /dev/null
+++ b/Zend/tests/use_function/ignore_constants.phpt
@@ -0,0 +1,23 @@
+--TEST--
+use function should ignore namespaced constants
+--FILE--
+<?php
+
+namespace foo {
+    const bar = 42;
+}
+
+namespace {
+    const bar = 43;
+}
+
+namespace {
+    use function foo\bar;
+    var_dump(bar);
+    echo "Done\n";
+}
+
+?>
+--EXPECT--
+int(43)
+Done
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 7696960..8013a1e 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1938,7 +1938,7 @@ int zend_do_begin_function_call(znode *function_name, 
zend_bool check_namespace
        char *lcname;
        char *is_compound = memchr(Z_STRVAL(function_name->u.constant), '\\', 
Z_STRLEN(function_name->u.constant));
 
-       zend_resolve_non_class_name(function_name, check_namespace TSRMLS_CC);
+       zend_resolve_function_name(function_name, check_namespace TSRMLS_CC);
 
        if (check_namespace && CG(current_namespace) && !is_compound) {
                        /* We assume we call function from the current namespace
@@ -2077,7 +2077,7 @@ void zend_do_begin_dynamic_function_call(znode 
*function_name, int ns_call TSRML
 }
 /* }}} */
 
-void zend_resolve_non_class_name(znode *element_name, zend_bool 
check_namespace TSRMLS_DC) /* {{{ */
+void zend_resolve_non_class_name(znode *element_name, zend_bool 
check_namespace, HashTable *current_import_sub TSRMLS_DC) /* {{{ */
 {
        znode tmp;
        int len;
@@ -2095,11 +2095,11 @@ void zend_resolve_non_class_name(znode *element_name, 
zend_bool check_namespace
                return;
        }
 
-       if (CG(current_import_function)) {
+       if (current_import_sub) {
                len = Z_STRLEN(element_name->u.constant)+1;
                lcname = 
zend_str_tolower_dup(Z_STRVAL(element_name->u.constant), len);
                /* Check if function matches imported name */
-               if (zend_hash_find(CG(current_import_function), lcname, len, 
(void**)&ns) == SUCCESS) {
+               if (zend_hash_find(current_import_sub, lcname, len, 
(void**)&ns) == SUCCESS) {
                        zval_dtor(&element_name->u.constant);
                        element_name->u.constant = **ns;
                        zval_copy_ctor(&element_name->u.constant);
@@ -2142,6 +2142,18 @@ void zend_resolve_non_class_name(znode *element_name, 
zend_bool check_namespace
 }
 /* }}} */
 
+void zend_resolve_function_name(znode *element_name, zend_bool check_namespace 
TSRMLS_DC) /* {{{ */
+{
+       zend_resolve_non_class_name(element_name, check_namespace, 
CG(current_import_function) TSRMLS_CC);
+}
+/* }}} */
+
+void zend_resolve_const_name(znode *element_name, zend_bool check_namespace 
TSRMLS_DC) /* {{{ */
+{
+       zend_resolve_non_class_name(element_name, check_namespace, NULL 
TSRMLS_CC);
+}
+/* }}} */
+
 void zend_do_resolve_class_name(znode *result, znode *class_name, int 
is_static TSRMLS_DC) /* {{{ */
 {
        char *lcname;
@@ -5644,7 +5656,7 @@ void zend_do_fetch_constant(znode *result, znode 
*constant_container, znode *con
                                break;
                        }
 
-                       zend_resolve_non_class_name(constant_name, 
check_namespace TSRMLS_CC);
+                       zend_resolve_const_name(constant_name, check_namespace 
TSRMLS_CC);
 
                        if(!compound) {
                                fetch_type |= IS_CONSTANT_UNQUALIFIED;
@@ -5656,7 +5668,7 @@ void zend_do_fetch_constant(znode *result, znode 
*constant_container, znode *con
                case ZEND_RT:
                        compound = memchr(Z_STRVAL(constant_name->u.constant), 
'\\', Z_STRLEN(constant_name->u.constant));
 
-                       zend_resolve_non_class_name(constant_name, 
check_namespace TSRMLS_CC);
+                       zend_resolve_const_name(constant_name, check_namespace 
TSRMLS_CC);
 
                        if(zend_constant_ct_subst(result, 
&constant_name->u.constant, 1 TSRMLS_CC)) {
                                break;
diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index f2078ed..066c517 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -437,7 +437,9 @@ ZEND_API char *zend_get_compiled_filename(TSRMLS_D);
 ZEND_API int zend_get_compiled_lineno(TSRMLS_D);
 ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D);
 
-void zend_resolve_non_class_name(znode *element_name, zend_bool 
check_namespace TSRMLS_DC);
+void zend_resolve_non_class_name(znode *element_name, zend_bool 
check_namespace, HashTable *current_import_sub TSRMLS_DC);
+void zend_resolve_function_name(znode *element_name, zend_bool check_namespace 
TSRMLS_DC);
+void zend_resolve_const_name(znode *element_name, zend_bool check_namespace 
TSRMLS_DC);
 void zend_resolve_class_name(znode *class_name, ulong fetch_type, int 
check_ns_name TSRMLS_DC);
 ZEND_API const char* zend_get_compiled_variable_name(const zend_op_array 
*op_array, zend_uint var, int* name_len);


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

Reply via email to