Skip to content

Commit 6b385eb

Browse files
Danackigorw
authored andcommitted
Removed assumption that \\ will be present
The function zend_add_ns_func_name_literal is called if the parser finds a function that is not in the global or current namespace. It assumes such a function will have a \\ in it, which is no longer true with the use function patch. The code change above removes that assumption and makes the test work: PASS use and use function with the same alias [Zend/tests/use_function/conflicting_use_alias.phpt]
1 parent 2dbbb8a commit 6b385eb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Zend/zend_compile.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,16 @@ int zend_add_ns_func_name_literal(zend_op_array *op_array, const zval *zv TSRMLS
426426
lc_literal = zend_add_literal(CG(active_op_array), &c TSRMLS_CC);
427427
CALCULATE_LITERAL_HASH(lc_literal);
428428

429-
ns_separator = (const char*)zend_memrchr(Z_STRVAL_P(zv), '\\', Z_STRLEN_P(zv)) + 1;
430-
lc_len = Z_STRLEN_P(zv) - (ns_separator - Z_STRVAL_P(zv));
431-
lc_name = zend_str_tolower_dup(ns_separator, lc_len);
432-
ZVAL_STRINGL(&c, lc_name, lc_len, 0);
433-
lc_literal = zend_add_literal(CG(active_op_array), &c TSRMLS_CC);
434-
CALCULATE_LITERAL_HASH(lc_literal);
429+
ns_separator = (const char*)zend_memrchr(Z_STRVAL_P(zv), '\\', Z_STRLEN_P(zv));
430+
431+
if (ns_separator != NULL) {
432+
ns_separator += 1;
433+
lc_len = Z_STRLEN_P(zv) - (ns_separator - Z_STRVAL_P(zv));
434+
lc_name = zend_str_tolower_dup(ns_separator, lc_len);
435+
ZVAL_STRINGL(&c, lc_name, lc_len, 0);
436+
lc_literal = zend_add_literal(CG(active_op_array), &c TSRMLS_CC);
437+
CALCULATE_LITERAL_HASH(lc_literal);
438+
}
435439

436440
return ret;
437441
}

0 commit comments

Comments
 (0)