'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.
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
'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.
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...
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'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.
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:
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...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'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.
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.
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
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.
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...
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 JayachandranA 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.
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:
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.
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 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.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.
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?
'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.
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
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?'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.
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
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?'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.
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");
?
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
Full path works without problem.
"Daniel Convissor" danielc@analysisandsolutions.com wrote in message
news:20040505025848.GA18650@panix.com...
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
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?
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");
?
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...
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?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");
?