--- /dev/null
+--TEST--
+Bug #43343 (Variable class name)
+--FILE--
+<?php
+namespace Foo;
+class Bar { }
+$foo = 'bar';
+var_dump(new namespace::$foo);
+?>
+--EXPECTF--
+Fatal error: Cannot use 'namespace' as a class name in %sbug43343.php on line 5
--- /dev/null
+--TEST--
+Bug #43344.1 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+function f1($a=bar) {
+ return $a;
+}
+function f2($a=array(bar)) {
+ return $a[0];
+}
+function f3($a=array(bar=>0)) {
+ reset($a);
+ return key($a);
+}
+echo bar."\n";
+echo f1()."\n";
+echo f2()."\n";
+echo f3()."\n";
+?>
+--EXPECTF--
+Notice: Use of undefined constant bar - assumed 'bar' in %sbug43344_1.php on line 13
+bar
+
+Notice: Use of undefined constant bar - assumed 'bar' in %sbug43344_1.php on line 3
+bar
+
+Notice: Use of undefined constant bar - assumed 'bar' in %sbug43344_1.php on line 6
+bar
+
+Notice: Use of undefined constant bar - assumed 'bar' in %sbug43344_1.php on line 9
+bar
--- /dev/null
+--TEST--
+Bug #43344.10 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+echo namespace::bar."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'bar' in %sbug43344_10.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.11 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+function f($a=namespace::bar) {
+ return $a;
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'bar' in %sbug43344_11.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.12 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+function f($a=array(namespace::bar)) {
+ return $a[0];
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'bar' in %sbug43344_12.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.13 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+function f($a=array(namespace::bar=>0)) {
+ reset($a);
+ return key($a);
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'bar' in %sbug43344_13.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.2 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+echo Foo::bar."\n";
+?>
+--EXPECTF--
+Fatal error: Class 'Foo::Foo' not found in %sbug43344_2.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.3 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+function f($a=Foo::bar) {
+ return $a;
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Class 'Foo::Foo' not found in %sbug43344_3.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.4 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+function f($a=array(Foo::bar)) {
+ return $a[0];
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Class 'Foo::Foo' not found in %sbug43344_4.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.5 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+function f($a=array(Foo::bar=>0)) {
+ reset($a);
+ return key($a);
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Class 'Foo::Foo' not found in %sbug43344_5.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.6 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+echo namespace::bar."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'Foo::bar' in %sbug43344_6.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.7 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+function f($a=namespace::bar) {
+ return $a;
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'Foo::bar' in %sbug43344_7.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.8 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+function f($a=array(namespace::bar)) {
+ return $a[0];
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'Foo::bar' in %sbug43344_8.php on line %d
--- /dev/null
+--TEST--
+Bug #43344.9 (Wrong error message for undefined namespace constant)
+--FILE--
+<?php
+namespace Foo;
+function f($a=array(namespace::bar=>0)) {
+ reset($a);
+ return key($a);
+}
+echo f()."\n";
+?>
+--EXPECTF--
+Fatal error: Undefined constant 'Foo::bar' in %sbug43344_9.php on line %d
057: Usage of 'namespace' in compound names (inside namespase)
--FILE--
<?php
-namespace test::ns1;
+namespace Test::ns1;
const C = "const ok\n";
zend_arg_info *cur_arg_info;
if (class_type->op_type == IS_CONST &&
+ Z_TYPE(class_type->u.constant) == IS_STRING &&
Z_STRLEN(class_type->u.constant) == 0) {
/* Usage of namespace as class name not in namespace */
zval_dtor(&class_type->u.constant);
zend_op *opline;
if (class_name->op_type == IS_CONST &&
+ Z_TYPE(class_name->u.constant) == IS_STRING &&
Z_STRLEN(class_name->u.constant) == 0) {
/* Usage of namespace as class name not in namespace */
zval_dtor(&class_name->u.constant);
ulong fetch_type = 0;
if (class_name->op_type == IS_CONST &&
+ Z_TYPE(class_name->u.constant) == IS_STRING &&
Z_STRLEN(class_name->u.constant) == 0) {
/* namespace::func() not in namespace */
zval_dtor(&class_name->u.constant);
+ if (CG(current_namespace)) {
+ znode tmp;
+
+ tmp.op_type = IS_CONST;
+ tmp.u.constant = *CG(current_namespace);
+ zval_copy_ctor(&tmp.u.constant);
+ zend_do_build_namespace_name(&tmp, &tmp, method_name TSRMLS_CC);
+ *method_name = tmp;
+ }
return zend_do_begin_function_call(method_name, 0 TSRMLS_CC);
}
ulong fetch_type = 0;
znode tmp;
+ if (constant_container &&
+ constant_container->op_type == IS_CONST &&
+ Z_TYPE(constant_container->u.constant) == IS_STRING &&
+ Z_STRLEN(constant_container->u.constant) == 0) {
+ /* namespace::const */
+ zval_dtor(&constant_container->u.constant);
+ check_namespace = 1;
+ constant_container = NULL;
+ fetch_type = ZEND_FETCH_CLASS_RT_NS_CHECK | IS_CONSTANT_RT_NS_CHECK;;
+ }
+
switch (mode) {
case ZEND_CT:
if (constant_container) {
zend_do_fetch_class_name(NULL, constant_container, constant_name TSRMLS_CC);
*result = *constant_container;
result->u.constant.type = IS_CONSTANT | fetch_type;
- } else if (!zend_constant_ct_subst(result, &constant_name->u.constant TSRMLS_CC)) {
+ } else if (fetch_type || !zend_constant_ct_subst(result, &constant_name->u.constant TSRMLS_CC)) {
if (check_namespace && CG(current_namespace)) {
/* We assume we use constant from the current namespace
if it is not prefixed. */
zval_copy_ctor(&tmp.u.constant);
zend_do_build_namespace_name(&tmp, &tmp, constant_name TSRMLS_CC);
*constant_name = tmp;
- fetch_type = IS_CONSTANT_RT_NS_CHECK;
+ fetch_type |= IS_CONSTANT_RT_NS_CHECK;
}
*result = *constant_name;
result->u.constant.type = IS_CONSTANT | fetch_type;
}
break;
case ZEND_RT:
- if (constant_container &&
- constant_container->op_type == IS_CONST &&
- Z_STRLEN(constant_container->u.constant) == 0) {
- /* Usage of namespace as class name not in namespace */
- zval_dtor(&constant_container->u.constant);
- constant_container = NULL;
- check_namespace = 0;
- }
-
if (constant_container ||
!zend_constant_ct_subst(result, &constant_name->u.constant TSRMLS_CC)) {
zend_op *opline;
tmp.u.constant = *CG(current_namespace);
zval_copy_ctor(&tmp.u.constant);
constant_container = &tmp;
- fetch_type = IS_CONSTANT_RT_NS_CHECK;
+ fetch_type |= IS_CONSTANT_RT_NS_CHECK;
}
opline = get_next_op(CG(active_op_array) TSRMLS_CC);
opline->opcode = ZEND_FETCH_CONSTANT;
- opline->extended_value = fetch_type & ~ZEND_FETCH_CLASS_RT_NS_NAME;
+ opline->extended_value = fetch_type & ~ZEND_FETCH_CLASS_RT_NS_NAME;
opline->result.op_type = IS_TMP_VAR;
opline->result.u.var = get_temporary_variable(CG(active_op_array));
if (constant_container) {
if (prefix) {
*result = *prefix;
+ if (Z_TYPE(result->u.constant) == IS_STRING &&
+ Z_STRLEN(result->u.constant) == 0) {
+ /* namespace:: */
+ if (CG(current_namespace)) {
+ znode tmp;
+
+ zval_dtor(&result->u.constant);
+ tmp.op_type = IS_CONST;
+ tmp.u.constant = *CG(current_namespace);
+ zval_copy_ctor(&tmp.u.constant);
+ zend_do_build_namespace_name(result, NULL, &tmp TSRMLS_CC);
+ }
+ }
} else {
result->op_type = IS_CONST;
Z_TYPE(result->u.constant) = IS_STRING;
is_ref = Z_ISREF_P(p);
if (!zend_get_constant_ex(p->value.str.val, p->value.str.len, &const_value, scope, Z_REAL_TYPE_P(p) TSRMLS_CC)) {
- if ((colon = memchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p))) && colon[1] == ':') {
- zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p));
+ if ((colon = zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p))) &&
+ colon > Z_STRVAL_P(p) &&
+ *(colon-1) == ':') {
+ if ((Z_TYPE_P(p) & IS_CONSTANT_RT_NS_CHECK) == 0) {
+ zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p));
+ } else if (Z_TYPE_P(p) & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error(E_ERROR, "Undefined constant '%s'", Z_STRVAL_P(p));
+ }
+ Z_STRLEN_P(p) -= ((colon - Z_STRVAL_P(p)) + 1);
+ if (inline_change) {
+ colon = estrndup(colon + 1, Z_STRLEN_P(p));
+ efree(Z_STRVAL_P(p));
+ Z_STRVAL_P(p) = colon;
+ } else {
+ Z_STRVAL_P(p) = colon + 1;
+ }
+ } else if (Z_TYPE_P(p) & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error(E_ERROR, "Undefined constant '%s'", Z_STRVAL_P(p));
}
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", Z_STRVAL_P(p), Z_STRVAL_P(p));
p->type = IS_STRING;
continue;
}
if (!zend_get_constant_ex(str_index, str_index_len - 3, &const_value, scope, str_index[str_index_len - 2] TSRMLS_CC)) {
- if ((colon = memchr(str_index, ':', str_index_len - 3)) && colon[1] == ':') {
- zend_error(E_ERROR, "Undefined class constant '%s'", str_index);
- }
+ if ((colon = zend_memrchr(str_index, ':', str_index_len - 3)) &&
+ colon > str_index &&
+ *(colon-1) == ':') {
+ if ((str_index[str_index_len - 2] & IS_CONSTANT_RT_NS_CHECK) == 0) {
+ zend_error(E_ERROR, "Undefined class constant '%s'", str_index);
+ } else if (str_index[str_index_len - 2] & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error(E_ERROR, "Undefined constant '%s'", str_index);
+ }
+ str_index_len -= ((colon - str_index) + 1);
+ str_index = colon + 1;
+ } else if (str_index[str_index_len - 2] & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error(E_ERROR, "Undefined constant '%s'", str_index);
+ }
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index);
ZVAL_STRINGL(&const_value, str_index, str_index_len-3, 1);
}
class_name:
T_STRING { $$ = $1; }
| T_STATIC { $$.op_type = IS_CONST; ZVAL_STRINGL(&$$.u.constant, "static", sizeof("static")-1, 1);}
- | T_NAMESPACE {if (CG(current_namespace)) { $1.op_type = IS_CONST; $1.u.constant = *CG(current_namespace); zval_copy_ctor(&$1.u.constant); zend_do_build_namespace_name(&$$, NULL, &$1 TSRMLS_CC); } else { $$.op_type = IS_CONST; ZVAL_EMPTY_STRING(&$$.u.constant); } }
+ | T_NAMESPACE { $$.op_type = IS_CONST; ZVAL_EMPTY_STRING(&$$.u.constant); }
| T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_build_namespace_name(&$$, NULL, &$2 TSRMLS_CC); }
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_build_namespace_name(&$$, &$1, &$3 TSRMLS_CC); }
;
fully_qualified_class_name:
T_STRING { $$ = $1; }
- | T_NAMESPACE {if (CG(current_namespace)) { $1.op_type = IS_CONST; $1.u.constant = *CG(current_namespace); zval_copy_ctor(&$1.u.constant); zend_do_build_namespace_name(&$$, NULL, &$1 TSRMLS_CC); } else { $$.op_type = IS_CONST; ZVAL_EMPTY_STRING(&$$.u.constant); } }
+ | T_NAMESPACE { $$.op_type = IS_CONST; ZVAL_EMPTY_STRING(&$$.u.constant); }
| T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_build_namespace_name(&$$, NULL, &$2 TSRMLS_CC); }
| fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_build_namespace_name(&$$, &$1, &$3 TSRMLS_CC); }
;
if (OP1_TYPE == IS_UNUSED) {
if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s'", Z_STRVAL(opline->op2.u.constant));
+ }
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));
zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var);
ZEND_VM_NEXT_OPCODE();
} else if ((opline->extended_value & IS_CONSTANT_RT_NS_CHECK) != 0) {
- if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s::%s'", Z_STRVAL(opline->op1.u.constant), Z_STRVAL(opline->op2.u.constant));
+ } else if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));
if (IS_CONST == IS_UNUSED) {
if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s'", Z_STRVAL(opline->op2.u.constant));
+ }
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));
zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var);
ZEND_VM_NEXT_OPCODE();
} else if ((opline->extended_value & IS_CONSTANT_RT_NS_CHECK) != 0) {
- if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s::%s'", Z_STRVAL(opline->op1.u.constant), Z_STRVAL(opline->op2.u.constant));
+ } else if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));
if (IS_VAR == IS_UNUSED) {
if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s'", Z_STRVAL(opline->op2.u.constant));
+ }
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));
zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var);
ZEND_VM_NEXT_OPCODE();
} else if ((opline->extended_value & IS_CONSTANT_RT_NS_CHECK) != 0) {
- if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s::%s'", Z_STRVAL(opline->op1.u.constant), Z_STRVAL(opline->op2.u.constant));
+ } else if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));
if (IS_UNUSED == IS_UNUSED) {
if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s'", Z_STRVAL(opline->op2.u.constant));
+ }
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));
zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var);
ZEND_VM_NEXT_OPCODE();
} else if ((opline->extended_value & IS_CONSTANT_RT_NS_CHECK) != 0) {
- if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
+ if (opline->extended_value & ZEND_FETCH_CLASS_RT_NS_CHECK) {
+ zend_error_noreturn(E_ERROR, "Undefined constant '%s::%s'", Z_STRVAL(opline->op1.u.constant), Z_STRVAL(opline->op2.u.constant));
+ } else if (!zend_get_constant(Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",
Z_STRVAL(opline->op2.u.constant),
Z_STRVAL(opline->op2.u.constant));