php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22395 Namespaces overwrite preexisting namespaces
Submitted: 2003-02-24 10:02 UTC Modified: 2003-06-03 15:57 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: andrew at evilwalrus dot com Assigned: zeev (profile)
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5CVS-2003-02-24 (dev) OS: WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrew at evilwalrus dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-24 11:06 UTC] wez@php.net
Assigning to Zeev so that this doesn't get lost.
 [2003-04-18 18:25 UTC] thekid at thekid dot de
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;
 [2003-06-03 15:57 UTC] sterling@php.net
Namespaces no longer supported, not a bug anymore. :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 09:01:38 2025 UTC