nested includes fails?

php.internals

Tumurbaatar S.

22 years ago
'common.php' contains some class definition and PHP5 fails with 'PHP Fatal error: Cannot redeclare class ... in common.php...' when script C.php starts. The file including map is: A.php: require_once(common.php) B.php: require_once(common.php) C.php: require_once(A.php) require_once(B.php) That is bug? When only one file is included (A or B), the contents of 'common.php' is available, i.e. nested require works. Only fails when nested and multiple require. P.S. I use PHP5 RC2 running as CGI on WinXP/IIS.

Kamesh Jayachandran

22 years ago
Hi, It does not seem to happen in Linux. I had similar issue with Netware. The issue was with my script. The issue can be, In A.php you might have require_once("common.php"); In A.php you might have require_once("Common.Php"); For windows file system 'common.php', 'Common.php', 'CoMmOn.PhP' and all such combinations are same. But for PHP each one are different so it would try to load many times and hence the fatal error. With regards Kamesh Jayachandran On Tue, 2004-05-04 at 10:55, Tumurbaatar S. wrote:

Tumurbaatar S.

22 years ago
All filepaths used within require_once() are lowercase. I use relative paths for include, depending on what directory a file located in, my requires look like 'inc/common.php' or 'common.php' or '../inc/common.php'. And it seems that PHP5 for Windows require() does some error on translating these relative paths. Generally, it (PHP5) accesses these paths correctly, but in its lookup table for includes (if such thing exists?) it stores these paths as is. I converted all my include param-s to absolute paths as 'c:/.../somefile.php' and now my app works well. "Kamesh Jayachandran" <kameshj@fastmail.fm> wrote in message news:1083649378.20045.3.camel@linux.local...

Andi Gutmans

22 years ago
This does sound like a bug because it's supposed to save the translated one in the lookup table. Can you give us some more info? It sounds as if you did take a look at the code. At 04:31 PM 5/4/2004 +0900, Tumurbaatar S. wrote:

Tumurbaatar S.

22 years ago
A brief directory structure: "e:\...\myapp\" - this my web apps root and it contains several subdirs: "e:\...\myapp\members\" - a normal, web shared subdir "e:\...\myapp\inc\" - an include subdir where are located all my include files and this subdir is not web shared (though my Inetpub dir is located in C:, I use IIS's virtual app/dir located in a different volume E:) The above "inc" subdir contains "common.php" which is used by all other script files located anywhere under app root and subdirs. So if a script is located in the "inc" subdir, then it may start with: <?php require_once('common.php') ?> If a script is in the root dir, then: <?php require_once('inc/common.php') ?> and if it is in other subdirs (e.g. "members"): <?php require_once('../inc/common.php') ?> Finally, when my script located in 'members' needs some include file from the "inc" dir, I include it in this manner: <?php require_once('../inc/some_include.php') ?> and I do not include "common.php" directly because "some_include.php" starts with: <?php require_once('common.php') ?> I.e. a rule is: a script does not include "common.php" if it includes some other include file because that include file already includes "common.php". That works fine untill I included 2 and more files: <?php require_once('../inc/some_include.php') ?> <?php require_once('../inc/other_include.php') ?> where each of these include files includes "common.php". In this case, "common.php" is included in a calling script file 2 times, even "require_once()" is used. And this leads to a trouble. Currently, I use absolute pathes hoping that when my app moves to Linux/Appache, relative pathes will work normally.

Kamesh Jayachandran

22 years ago
Any reason why you want to use require_once with same filename with different paths? Why don't you set a include_dir as your e:\...\myapp\inc and just require 'common.php'. With regards Kamesh Jayachandran On Tue, 2004-05-04 at 15:49, Tumurbaatar S. wrote:

Tumurbaatar S.

22 years ago
I'm not familiar with Linux/Apache, but if they run as Windows/IIS pair, then I'm afraid that "php.ini" would be shared among all developers hosting on a single server and my include dir would expose its contents to other app-s. Though below may be another workaround: <?php ini_set('include_dir', '....'); include('blahblahblah'); ?> "Kamesh Jayachandran" <kameshj@fastmail.fm> wrote in message news:1083666449.25843.3.camel@linux.local...

Andi Gutmans

22 years ago
He shouldn't have to use this. It should work. At 03:57 PM 5/4/2004 +0530, Kamesh Jayachandran wrote:

Andi Gutmans

22 years ago
This is supposed to work and if it doesn't, then it's a bug. I'll try and find time to see if I can reproduce it. At 07:19 PM 5/4/2004 +0900, Tumurbaatar S. wrote:

Ilya Sher

22 years ago
Tumurbaatar S. wrote:
> 'common.php' contains some class definition and PHP5 fails with > 'PHP Fatal error: Cannot redeclare class ... in common.php...' when > script C.php starts. The file including map is: > > A.php: require_once(common.php) > B.php: require_once(common.php) > C.php: > require_once(A.php) > require_once(B.php) > > That is bug? When only one file is included (A or B), > the contents of 'common.php' is available, i.e. nested require > works. Only fails when nested and multiple require. > > P.S. I use PHP5 RC2 running as CGI on WinXP/IIS. >
That seems to be the correct behaviour for both PHP5 and PHP4. A class should never be defined twice - but that's the case when you include or execute somehow else the code with class definition (common.php) more than once.

Ilya Sher

22 years ago
Ilya Sher wrote:
> Tumurbaatar S. wrote: > >> 'common.php' contains some class definition and PHP5 fails with >> 'PHP Fatal error: Cannot redeclare class ... in common.php...' when >> script C.php starts. The file including map is: >> >> A.php: require_once(common.php) >> B.php: require_once(common.php) >> C.php: >> require_once(A.php) >> require_once(B.php) >> >> That is bug? When only one file is included (A or B), >> the contents of 'common.php' is available, i.e. nested require >> works. Only fails when nested and multiple require. >> >> P.S. I use PHP5 RC2 running as CGI on WinXP/IIS. >> > That seems to be the correct behaviour for > both PHP5 and PHP4.
Really sorry for misleading. Should read "... for PHP4" and I assume for PHP5.

Jevon Wright

22 years ago
I tested it on PHP 5 RC1, Win XP SP1, IIS 5.1 running as CGI - it didn't fail. I tried it on PHP 5 RC2, Win XP SP1, IIS 5.1 running as CGI - it didn't fail then, either. (Calling c.php) a.php <?php require_once("common.php"); ?> b.php <?php require_once("common.php"); ?> c.php <?php require_once("a.php"); require_once("b.php"); ?> common.php <?php class Foo { } ?> Jevon ----- Original Message ----- From: "Tumurbaatar S." <tumurbaatar@datacom.mn> To: <internals@lists.php.net> Sent: Tuesday, May 04, 2004 5:25 PM Subject: [PHP-DEV] nested includes fails?

Andi Gutmans

22 years ago
Can you give it a try with relative patches the way Tumurbaatar did? Andi At 11:41 PM 5/4/2004 +1200, Jevon Wright wrote:

Jevon Wright

22 years ago
Sorry for the delay... I didn't quite understand the problem, but I've tried to reproduce it: ----- \inc\a.php <?php class A { } ?> \inc\b.php <?php class B { } ?> \inc\common.php <?php require_once("a.php"); require_once("b.php"); ?> \inc\member.php <?php require_once("common.php"); class C { } ?> \inc\foo.php <?php require_once("common.php"); class D { } ?> ----- \member\member.php <?php require_once("../inc/common.php"); ?> \member\member2.php <?php require_once("../inc/member.php"); ?> \member\member3.php <?php require_once("../inc/member.php"); require_once("../inc/foo.php"); ?> ----- I can access \member.php, \member2.php and \member3.php all fine with no errors. Perhaps you've got a "common.php" in the \member directory? Because require_once("common.php") will use *that* common.php instead (and not the one in \inc\). Jevon ----- Original Message ----- From: "Andi Gutmans" <andi@zend.com> To: "Jevon Wright" <jevon@jevon.org>; "Tumurbaatar S." <tumurbaatar@datacom.mn>; <internals@lists.php.net> Sent: Tuesday, May 04, 2004 11:50 PM Subject: Re: [PHP-DEV] nested includes fails?
> Can you give it a try with relative patches the way Tumurbaatar did? > > Andi > > At 11:41 PM 5/4/2004 +1200, Jevon Wright wrote: > >I tested it on PHP 5 RC1, Win XP SP1, IIS 5.1 running as CGI - it didn't > >fail. > >I tried it on PHP 5 RC2, Win XP SP1, IIS 5.1 running as CGI - it didn't
fail

Tumurbaatar S.

22 years ago
Hi, Jevon, Mine is not so complex: //all files in 'inc' include 'common.php' \inc\a.php <?php require_once("common.php"); class A { } ?> \inc\b.php <?php require_once("common.php"); class B {} ?> //common.php does not include anything \inc\common.php <?php class C { } ?> //this works. Main scripts include 'common.php' indirectly \member\member.php <?php require_once("../inc/a.php"); ?> //this fails:redeclaration of class C \member\member3.php <?php require_once("../inc/a.php"); require_once("../inc/b.php"); ?>

Daniel Convissor

22 years ago
On Wed, May 05, 2004 at 10:32:26AM +0900, Tumurbaatar S. wrote:
> require_once("common.php");
What happens if you use the full path for ALL of your require_once statements? --Dan
-- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y data intensive web and database programming http://www.AnalysisAndSolutions.com/ 4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

Tumurbaatar S.

22 years ago
Full path works without problem. "Daniel Convissor" <danielc@analysisandsolutions.com> wrote in message news:20040505025848.GA18650@panix.com...

Arjen Warendorff

22 years ago
Hello, I have played around with the Reflection API, missed some features and have some questions: At the moment there is no way of checking if a default parameter has a value, and if so, to get it's value. Example: function foo($bar = TRUE) {} The default value for $bar would be TRUE in this example (maybe a "hasDefaultValue()" and a "getDefaultValue()" method?). The ReflectionParameter method "allowsNull()" doesn't seem to return anything else then (bool)TRUE ?? The ReflectionFunction method "getStartLine()" would be, in my opinion) become even more usefull if you had something like a "getLine()" method which should return the source code on that line, but i might be out of my league here. :) With kind regards, - Arjen

Jevon Wright

22 years ago
----- Original Message ----- From: "Arjen Warendorff" <awarendorff@e-sites.nl> To: "'PHP Internals List'" <internals@lists.php.net> Sent: Wednesday, May 05, 2004 7:33 PM Subject: [PHP-DEV] Reflection API : Feature request and question
> Hello, > > I have played around with the Reflection API, missed some features and
have
> some questions: > > At the moment there is no way of checking if a default parameter has a > value, and if so, to get it's value. Example: > function foo($bar = TRUE) {} > The default value for $bar would be TRUE in this example (maybe a > "hasDefaultValue()" and a "getDefaultValue()" method?).
I reported this in my bug: http://bugs.php.net/bug.php?id=28241 It was suspended until PHP 5.1... but yes, I really think the Reflection API needs this!
> The ReflectionFunction method "getStartLine()" would be, in my opinion) > become even more usefull if you had something like a "getLine()" method > which should return the source code on that line, but i might be out of my > league here. :)
Couldn't you do this in userland? Which the PHP internals seem so obsessed about :D I don't know if this is truly useful - maybe if the PHP code is stored in memory anyway, and it doesn't introduce a performance penalty...? Jevon

Andi Gutmans

22 years ago
At 09:33 AM 5/5/2004 +0200, Arjen Warendorff wrote:
>The ReflectionParameter method "allowsNull()" doesn't seem to return >anything else then (bool)TRUE ??
Because today this still isn't supported (except for maybe in internal functions). Today all parameters allow NULL :) Andi

Jevon Wright

22 years ago
I tried this and it didn't fail... Jevon ----- Original Message ----- From: "Tumurbaatar S." <tumurbaatar@datacom.mn> To: <internals@lists.php.net> Sent: Wednesday, May 05, 2004 1:32 PM Subject: Re: [PHP-DEV] nested includes fails?

Tumurbaatar S.

22 years ago
Yes, mine works too. After you reply I tested it without abs paths and that worked. May be there was some error in my include scripts because after my 1st post I did many changes in them. Though I wonder what was wrong in my prior code. Thank you all! "Jevon Wright" <jevon@jevon.org> wrote in message news:059b01c4326a$bc9f3890$0a00a8c0@home.jevon.org...