Bug #11507 Updated: Function within a function namespace
| From: | gary at conduit-it dot com | Date: | Tue, 19 Jun 2001 02:47:11 +0000 |
| Subject: | Bug #11507 Updated: Function within a function namespace | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-57060@lists.php.net to get a copy of this message | ||
ID: 11507
User Update by: gary@conduit-it.com
Status: Open
Old-Bug Type: Feature/Change Request
Bug Type: *Programming Data Structures
Operating system: FreeBSD
PHP Version: 4.0.5
Description: Function within a function namespace
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
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=11507