Ajax & require

J

Jason Carlton

I'm having a hard time tracking down an error, so I'm hoping you guys
can help me save a few hours of work.

If I require a file in the parent page, do I need to require it again
in a child page called via Ajax in order to use it there?

Logic says that I do, but I'm getting an error that says:

Fatal error: Cannot redeclare xml2array() (previously declared in /
home/mydomain/public_html/includes/inc.xml2array.php:3)


TIA,

Jason
 
J

Jason Carlton

I'm having a hard time tracking down an error, so I'm hoping you guys
can help me save a few hours of work.

If I require a file in the parent page, do I need to require it again
in a child page called via Ajax in order to use it there?

Logic says that I do, but I'm getting an error that says:

Fatal error: Cannot redeclare xml2array() (previously declared in /
home/mydomain/public_html/includes/inc.xml2array.php:3)

TIA,

Jason


I'm still not sure of the answer, but for any future reader with a
similar error, using require_once() instead of require() solved the
problem.

- J
 
E

Erwin Moller

Jason Carlton schreef:
I'm still not sure of the answer, but for any future reader with a
similar error, using require_once() instead of require() solved the
problem.

- J

Hi,

You are asking a PHP question in a javascript group.
Don't. ;-)

For your information:
In PHP:
require(file): Includes the file and generates an error if it fails. (As
opposed to include()).
require_once(file): Includes the file ONLY if it hasn't been included
before. If it has been included before, this statement is ignored.

Apparantly you try to include the same file two times, and thus
redeclared xml2array, what generated the error.

It is better to fix your code in a serious way (= remove the second
require()), and not use require_once() to fix the problem.

For more information try comp.lang.php

Regards,
Erwin Moller


--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
 
J

Jason Carlton

Jason Carlton schreef:






Hi,

You are asking a PHP question in a javascript group.
Don't. ;-)


Ajax always makes it difficult to know where to ask these questions.
Had I asked this question in comp.lang.php, they would have said that
it's an Ajax question so it would belong in comp.lang.javascript.

We need an Ajax-specific NG.
 
T

Thomas 'PointedEars' Lahn

Jason said:
Jason Carlton schreef:
Fatal error: Cannot redeclare xml2array() (previously declared in /
home/mydomain/public_html/includes/inc.xml2array.php:3) [...]

I'm still not sure of the answer, but for any future reader with a
similar error, using require_once() instead of require() solved the
problem.

[...]
You are asking a PHP question in a javascript group.
Don't. ;-)

Ajax always makes it difficult to know where to ask these questions.
Had I asked this question in comp.lang.php, they would have said that
it's an Ajax question so it would belong in comp.lang.javascript.

Had you gotten yourself informed before posting what "Ajax" really is (and
read the error message carefully to begin with), you could have broken it
down for them to the PHP issue that it is. Besides, I do not think people
in comp.lang.php are so stupid not to see that it is a PHP problem, and you
should not assume that they are.
We need an Ajax-specific NG.

We don't.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top