Arno Kuhl wrote:
On 5/30/06, Arno Kuhl <akuhl@xxxxxxxxxxxx> wrote:
I understand the difference well enough, but I've never really understood
the reason for having both. Is it to help find errors in sloppy coding, or
is there a case where including a file more than once is desirable (and
won't cause an error)?
-----Original Message-----
From: chris smith [mailto:dmagick@xxxxxxxxx]
Sent: 30 May 2006 02:11
To: arno@xxxxxxxxxxxxxx
Cc: php-general@xxxxxxxxxxxxx
Subject: Re: how include works?
There was more of a difference earlier on.
On http://www.php.net/manual/en/function.require.php:
Note: Prior to PHP 4.0.2, the following applies: require() will
always attempt to read the target file, even if the line it's on never
executes.
Now it behaves the same way except for the failure method (require is
fatal, include is not).
--
I wasn't talking about the difference between require and include but rather
the difference between require and require_once (or include and
include_once). Why doesn't require just work the same way as require_once,
because I can't see the need for require -ing the same file more than once.
Possibly for someone that doesn't understand the purpose of functions, as
Peter suggested, but programming languages don't generally go out of their
way to cater for people who don't understand basic programming concepts.
OOP.
file "b.php"
<?php
require('a.php');
class b extends a {
}
?>
file "c.php"
<?php
require('a.php');
class c extends a {
}
?>
...
Using both class "c" and "a" within the same request would cause an
error because both are require'ing a.php.
This situation might come up when developing or using any sort of API -
your base methods (load, save, update, delete etc) are in "a.php" and
are overridden in the subclasses.
Using that API, class b might load up a user, class c might save
comments to the database - you need to load the user to check
permissions before you save to the database.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php