RE: [PHP] Require() vs Include()
| From: | Maxim Maletsky | Date: | Tue, 14 Nov 2000 09:22:26 +0000 |
| Subject: | RE: [PHP] Require() vs Include() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-25162@lists.php.net to get a copy of this message | ||
a small addition:
this is a piece of my code, I just gropped it here:
if( !$db_oracle_inc_def )
include "$DOCUMENT_ROOT/inc/db_oracle.inc";
as you can see there are no statement block (no brackets)
yet it perfectly wrong, I think what you read was related to the previouse
versions of php.
the code above runs on PHP 4.0.2pl2
Cheers!
-----Original Message-----
From: Lawrence.Sheed@dfait-maeci.gc.ca
[mailto:Lawrence.Sheed@dfait-maeci.gc.ca]
Sent: Tuesday, November 14, 2000 2:08 PM
To: gascsd@gascairlines.com; php-general@lists.php.net
Subject: RE: [PHP] Require() vs Include()
Just to be pedantic ;)
From the manual:
Because include() is a special language construct, you must enclose it
within a statement block if it is inside a conditional block
So
if ($x==$y) {
require ("xx.php");
}
else {
include ("yy.php");
}
BTW your output should still be correct, because the code in the require
isn't being run - it is however being added in before parsing by the php
preprocessor.
The include however, will not be added in if it doesn't get run.
Require is a throwback to #include from C days.
cheers,
Lawrence.
-----Original Message-----
From: Mark Peoples [mailto:gascsd@gascairlines.com]
Sent: November 14, 2000 12:56 PM
To: 'PHP General List. (E-mail)'
Subject: RE: [PHP] Require() vs Include()
Hi Maxim,
Suppose you have this:
--file1.php--
<?php print("\nin file1.php"); ?>
--file2.php--
<?php print("\nin file2.php"); ?>
Now, suppose you want to include certain files, based on conditions:
--test.php--
if($myCatVioletHasBlackFur == "no")
require(file1.php);
if($myCatVioletHasBlackFur == "yes")
include(file2.php);
Well, my cat, Violet <g>, has black fur, so the 2nd condition is valid, the
1st is false. However, require() is executed regardless, so, the output of
test.php is:
in file1.php
in file2.php
So, what if I change test.php to:
--test.php--
if($myCatVioletHasBlackFur == "no")
include(file1.php);
if($myCatVioletHasBlackFur == "yes")
include(file2.php);
Well, Violet still has black fur, so, the output is:
in file2.php
Hope this helps. =)
marco
-----Original Message-----
From: Maxim Maletsky [mailto:maxim.maletsky@japaninc.net]
Sent: Monday, November 13, 2000 9:21 PM
To: 'PHP General List. (E-mail)'
Subject: [PHP] Require() vs Include()
Hi,
A tiny question:
why to use require() when include() works just as well and even better when
there are some conditions like if{} ?
I ask it because although I read many articles on this issue I found no
reason for myself to use require() instead of include() and I have driven
some huge projects in PHP.
Why do I see these hardcore PHP gurus writing PHPLIB, mySQLadmin and
examples in their articles using require() where include() would fit just as
perfect?
WHERE THE TRIIIICK?
It escapes from me ...
Thanks.
Maxim Maletsky - maxim@j-door.com <mailto:maxim@j-door.com>
Webmaster, J-Door.com / J@pan Inc.
LINC Media, Inc.
TEL: 03-3499-2175 x 1271
FAX: 03-3499-3109
http://www.j-door.com <http://www.j-door.com/>
http://www.japaninc.net <http://www.japaninc.net/>
http://www.lincmedia.co.jp <http://www.lincmedia.co.jp/>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net