#23785 [Opn->Csd]: Namespaces and build-in-functions

From: Date: Thu, 05 Jun 2003 03:27:49 +0000
Subject: #23785 [Opn->Csd]: Namespaces and build-in-functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-41205@lists.php.net to get a copy of this message
 ID:               23785
 Updated by:       sterling@php.net
 Reported By:      zyxwvu at me2 dot pl
-Status:           Open
+Status:           Closed
 Bug Type:         Zend Engine 2 problem
 Operating System: Mandrake Linux 9
 PHP Version:      5CVS-2003-05-23 (dev)
 New Comment:

actually close.


Previous Comments:
------------------------------------------------------------------------

[2003-06-04 22:27:32] sterling@php.net

there are no namespaces in php.

------------------------------------------------------------------------

[2003-05-23 14:39:37] 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

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=23785&edit=1



Thread (3 messages)

« previous php.bugs (#41205) next »