From: zyxwvu at me2 dot pl
Operating system: Mandrake Linux 9
PHP version: 5CVS-2003-05-23 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: Namespaces and build-in-functions
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 bug report at http://bugs.php.net/?id=23785&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=23785&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=23785&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=23785&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=23785&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=23785&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=23785&r=support
Expected behavior: http://bugs.php.net/fix.php?id=23785&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=23785&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=23785&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=23785&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23785&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=23785&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=23785&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=23785&r=gnused