Hi,

Another solution I have used when I have to do conditional includes which
may cause the same page to be included twice....


At the top of the code to be included (the separate file) put something
like:

if ($theFileAlreadyInclude != 1) {

and at the bottom you may put:

}
$theFileAlreadyIncluded =1;

depending on the way your coding you may need make the variable global.

Hope this helps.

Gerard




-----Original Message-----
From: Jason Wood [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 26, 2001 3:43 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Error: Can't redeclare already declared function (PHP
3.0.15)


I had the same type of problem. ( i think)

I had one main page (say index.php) that had a bare bones html page.  No
functions or anything.
Then i had separate pages that would be included only if i was using them
(like, say, a category.php for displaying categories, then products.php for
showing products.)

I had a function called printlist();  that would create a drop down menu
with categories/subcategories;  this was in both category.php and
products.php.  Niether of those files were included at the same time though,
and it'd give me the redeclare error... what i did was rename the function
in each file (like for category.php, rename it to printlist1(); and then in
products.php rename it to printlist2();... this is a quick fix).  Let me
know if this was any help :)


--
Jason Wood
Chief Technology Officer
Expressive Tek, Inc.
407 Kehrs Mill Road
Ballwin, MO 63011
Phone 636.256.1362
www.expressivetek.com



"Patrick Dunford" <[EMAIL PROTECTED]> wrote in message
001501c15e27$1a738b80$bd84a7cb@patricks">news:001501c15e27$1a738b80$bd84a7cb@patricks...
> I have a script (let's call it a.php3) that brings in another script
b.php3
> with the include or require call.
>
> In script b.php3 there is an include or require call to bring in script
> c.php3.
>
> Script a.php3 after making one and only one include (the include is not
> repeated anywhere in a.php3) then calls a function x which is defined in
> script b.php3.
>
> The first time the function is called it executes without any problems.
The
> second time in which it is called, in exactly the same way, with the same
> parameters, it errors with the message
> Can't redeclare already declared function in c.php3 at line <the last line
> of the first function declaration in c.php3>
>
> The function is not actually named in the error message. This is the code
> block in c.php3 which the error occurs:
>
> <top of file>
> <?php
>
>  function getDirNames($sourceDir,$includeBase)
>  {
>   global $pathList;
>
>   function findAllDirsInDir($sourceDir)
>   {
>    global $pathList;
>    $dirHandle=opendir($sourceDir);
>    while (($subDir=readdir($dirHandle))!=false)
>    {
>     if (is_dir($sourceDir."/".$subDir))
>     {
>      if ($subDir != "." && $subDir != "..")
>      {
>       $dirList[] = $sourceDir."/".$subDir;
>       $pathList[] = $sourceDir."/".$subDir;
>      }
>     }
>    }
>    closedir($dirHandle);
>    return $dirList;
>   }; <<error occurs here>>
>
>   function buildDirList($sourceDir,$recurse)
>   {
>    $subDirList=findAllDirsInDir($sourceDir);
>    if (count($subDirList) != 0)
>     $recurse=true;
>    else
>     $recurse=false;
>    for($i=0; $i<count($subDirList);$i++)
>    {
>     $currentSubDir=$subDirList[$i];
>     if ($recurse==true)
>      buildDirList($currentSubDir,$recurse);
>    }
>   }
>
>   buildDirList($sourceDir,true);
>   if ($includeBase == TRUE)
>    $pathList[] = $sourceDir;
>   return $pathList;
>  }
>
> There are no multiple calls to include or require:
>
> * a.php3 which is the script that calls the function several times to
output
> data, contains only one call to include() that is not inside any kind of
> loop. It is called once just before the first function call.
>
> *b.php3 which is the script that is included by a.php3. It includes c.php3
> ONCE ONLY, NOT IN A LOOP.
>
> *c.php3 which is the script in which the error is occurring.
>
> Debugging b.php3 shows that the error message is thrown when execution
> reaches the line in which the function from c.php3 is called. Therefore I
> surmise that the error message is ambiguous.
>
>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to