Bug #11507 Updated: Function within a function namespace
| From: | jmoore@php.net | Date: | Sun, 17 Jun 2001 09:15:17 +0000 |
| Subject: | Bug #11507 Updated: Function within a function namespace | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-56992@lists.php.net to get a copy of this message | ||
ID: 11507
Updated by: jmoore
Reported By: gary@conduit-it.com
Status: Open
Old-Bug Type: Scripting Engine problem
Bug Type: Feature/Change Request
Operating system:
PHP Version: 4.0.5
Assigned To:
Comments:
Why not do somthing sensible like call a function that creates an array of callback references:
so
function blah() {
$foo = array();
$foo["render"] = "bar";
}
$foo["render"]() would call bar();
There is no mention of function namespaces in PHP's documentation at all and we have never
really seen the need for them. Changing to a feature/change request.
- James
Previous Comments:
---------------------------------------------------------------------------
[2001-06-15 18:07:01] gary@conduit-it.com
I have found that a function within a function takes a global namespace. Shouldn't the inside
function declaration remain inside the scope of the outer function? For example:
function add_number($num)
{
function add_one($num)
{
$num++;
return($num);
}
$num = add_one($num);
if($num <= 10)
{
$num = add_number($num);
}
return($num);
}
I know, why would anyone want to do this? I'll try to explain how I came about this.
We're writing a content management application. What I'm trying to do is write a function
that includes a file that has a function in it. The file may be included more than once on the page
depending on the designer's preference. Say we have an include file that generates a
"navigation block" on the page. It has a function specific to doing that task. The
nav-block may not appear on every page, so it's inefficient to include the function unless
I'm going to generate the nav-block. I therefore have to provide the function in the include
file along with the html and other php code to generate the nav-block when and where I want. I
wrote a function which I pass an ID to, which then includes the nav-block file. But, if I try to
put another copy of that same nav-block on the same page, I get the "Cannot redeclare..."
error. Yes, I could use a class structure, but we are trying to achieve a way of programming these
"blocks" in the most simplistic way by minizing the amount of php knowledge necessary.
If any of this is not clear, I'm willing to go to any length to explain and to find out if this
can be resolved. It's pretty important that we can do this. One of the main goals to our
software depends on this.
Thanks
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=11507&edit=2