mirror of
https://github.com/php/php-src.git
synced 2026-03-26 09:12:14 +01:00
Allowed multiple namespaces per file (Gregory)
This commit is contained in:
23
Zend/tests/ns_060.phpt
Normal file
23
Zend/tests/ns_060.phpt
Normal file
@@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
060: multiple namespaces per file
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Foo;
|
||||
use Bar::A as B;
|
||||
class A {}
|
||||
$a = new B;
|
||||
$b = new A;
|
||||
echo get_class($a)."\n";
|
||||
echo get_class($b)."\n";
|
||||
namespace Bar;
|
||||
use Foo::A as B;
|
||||
$a = new B;
|
||||
$b = new A;
|
||||
echo get_class($a)."\n";
|
||||
echo get_class($b)."\n";
|
||||
class A {}
|
||||
--EXPECT--
|
||||
Bar::A
|
||||
Foo::A
|
||||
Foo::A
|
||||
Bar::A
|
||||
@@ -5248,13 +5248,10 @@ void zend_do_namespace(znode *name TSRMLS_DC) /* {{{ */
|
||||
CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
|
||||
--num;
|
||||
}
|
||||
if (num > 0) {
|
||||
if (!CG(current_namespace) && num > 0) {
|
||||
zend_error(E_COMPILE_ERROR, "Namespace declaration statement has to be the very first statement in the script");
|
||||
}
|
||||
}
|
||||
if (CG(current_namespace)) {
|
||||
zend_error(E_COMPILE_ERROR, "Namespace cannot be declared twice");
|
||||
}
|
||||
lcname = zend_u_str_case_fold(Z_TYPE(name->u.constant), Z_UNIVAL(name->u.constant), Z_UNILEN(name->u.constant), 0, &lcname_len);
|
||||
if (((lcname_len == sizeof("self")-1) &&
|
||||
ZEND_U_EQUAL(Z_TYPE(name->u.constant), lcname, lcname_len, "self", sizeof("self")-1)) ||
|
||||
@@ -5264,7 +5261,17 @@ void zend_do_namespace(znode *name TSRMLS_DC) /* {{{ */
|
||||
}
|
||||
efree(lcname.v);
|
||||
|
||||
ALLOC_ZVAL(CG(current_namespace));
|
||||
if (CG(current_namespace)) {
|
||||
zval_dtor(CG(current_namespace));
|
||||
} else {
|
||||
ALLOC_ZVAL(CG(current_namespace));
|
||||
}
|
||||
if (CG(current_import)) {
|
||||
zend_hash_destroy(CG(current_import));
|
||||
efree(CG(current_import));
|
||||
CG(current_import) = NULL;
|
||||
}
|
||||
|
||||
*CG(current_namespace) = name->u.constant;
|
||||
}
|
||||
/* }}} */
|
||||
@@ -5407,7 +5414,7 @@ void zend_do_end_compilation(TSRMLS_D) /* {{{ */
|
||||
{
|
||||
if (CG(current_namespace)) {
|
||||
zval_dtor(CG(current_namespace));
|
||||
efree(CG(current_namespace));
|
||||
FREE_ZVAL(CG(current_namespace));
|
||||
CG(current_namespace) = NULL;
|
||||
}
|
||||
if (CG(current_import)) {
|
||||
|
||||
Reference in New Issue
Block a user