|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-24 10:02 UTC] andrew at evilwalrus dot com
The following code should (theoretically) generate a fatal error, as it overwrites a predefined namespace (tested on 'parent' and 'self' namespaces:
<?php
namespace parent
{
class foo
{
private $data;
function __construct($data)
{
$this->data = $data;
}
function debug()
{
print $this->data;
}
}
}
$foo = new parent::foo('Hello World!');
$foo->debug();
?>
----------------------------------------------------
I don't think this is done by design due to the fact that the predefined namespaces are in place to prevent this, and also for other uses.
~ Andrew Heebner
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 02:00:01 2025 UTC |
This can be fixed with this small extra check: Index: Zend/zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.412 diff -u -r1.412 zend_compile.c --- Zend/zend_compile.c 11 Apr 2003 17:30:41 -0000 1.412 +++ Zend/zend_compile.c 18 Apr 2003 23:24:12 -0000 @@ -3417,6 +3417,10 @@ zend_op *opline; zend_str_tolower(ns_name->u.constant.value.str.val, ns_name->u.constant.value.str.len); + if (!(strcmp(ns_name->u.constant.value.str.val, "main") && strcmp(ns_name->u.constant.value.str.val, "self") && + strcmp(ns_name->u.constant.value.str.val, "parent"))) { + zend_error(E_COMPILE_ERROR, "Cannot use '%s' as namespace name as it is reserved", ns_name->u.constant.value.str.val); + } if(zend_hash_find(&CG(global_namespace).class_table, ns_name->u.constant.value.str.val, ns_name->u.constant.value.str.len+1, (void **)&pns) == SUCCESS) { ns = *pns;