php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23785 Namespaces and build-in-functions
Submitted: 2003-05-23 14:39 UTC Modified: 2003-06-04 22:27 UTC
From: zyxwvu at me2 dot pl Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2003-05-23 (dev) OS: Mandrake Linux 9
Private report: No CVE-ID: None
 [2003-05-23 14:39 UTC] zyxwvu at me2 dot pl
When I ran this PHP script:

<?php

namespace ns{

		function zend_version(){
			echo zend_version();
		}

		function make_php_happy(){
			echo "I'm happy!!!";
		}

	}

	ns::make_php_happy();
	ns::zend_version();
?>

I noticed that my system works veeery slow. I tried to kill the server process, but i had to pick "Reset". After this history I started to analyze whole problem and I found interesing thing. In my opinion, if we make in the namespace's function (which has got the same name, like build-in PHP function, or also global function created by user)
<?php
function foo(){
  echo 'foo';
}

namespace x{
  function foo(){
    foo();
  }

}

x::foo();
?>
The namespace's function foo() shouldn't call itself, but global function foo(), should it? The same way is with the build-in-functions. If we want to make a recursive (function calls itself), we should use "x::foo();" to do it.

I tried to fix this bug myself, but I only found the place, where the error is: php-5/Zend/zend_compile.h, on line 1184, function "zend_do_begin_function_call()". Oryginally we had these lines in this place:
-----------------------------------
	switch (function->type) {
		case ZEND_USER_FUNCTION:	{
				zend_op_array *op_array = (zend_op_array *) function;
									zend_stack_push(&CG(function_call_stack), (void *) &op_array, sizeof(zend_function *));
					break;
------------------------------------
I replaced it by this code:
------------------------------------
	switch (function->type) {
		case ZEND_USER_FUNCTION:	{
				if(function -> common.ns != CG(active_namespace)){
					zend_op_array *op_array = (zend_op_array *) function;
				
					zend_stack_push(&CG(function_call_stack), (void *) &op_array, sizeof(zend_function *));
					break;

				}else{
					zend_error(E_COMPILE_ERROR, "Namespace error - try to use global function!");
				}
			}
------------------------------------
And then, when I try to run these PHP scripts, PHP generates:
"Fatal error: Namespace error - try to use global function! in file.php on line 6"
or something like that :)

System params:
 Mandrake Linux 9
 Apache 2.0.45
 PHP 5.0.0-dev

PHP configuration:
 -- with-apxs2 --with-mysql --with-pgsql --with-zlib --with-gd

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-04 22:27 UTC] sterling@php.net
there are no namespaces in php.
 [2003-06-04 22:27 UTC] sterling@php.net
actually close.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 21:01:33 2025 UTC