note 111521 added to function.require-once
| From: | bimal at sanjaal dot com | Date: | Thu, 28 Feb 2013 17:37:51 +0000 |
| Subject: | note 111521 added to function.require-once | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193752@lists.php.net to get a copy of this message | ||
Sometimes, you need to maintain the order of includes!
When your file being included needs some resources (like class definition, function body, etc), the
file that has those resources should be included first.
However, this is not necessary if you write whole things within a single file :-)
<?php
# class.a.inc.php: Defines an arbitrary class named 'a'
require_once('class.a.inc.php');
## class a { ... }
# class.b.inc.php: Defines an arbitrary class named 'b'
# class 'b' depends on the existence of class 'a'
require_once('class.b.inc.php');
## class b extends class a { ... }
?>
This does not apply strictly when you define classes/functions within the same file:
<?php
# This class needs class 'a' which is not yet defined
class b
extends a
{
}
# You can define this class class later on, within the same file
class a
{
}
?>
In the first example, if you include class.b.inc.php earlier than class.b.inc.a, there is a havoc.
----
Server IP: 69.147.83.199
Probable Submitter: 110.34.4.242
----
Manual Page -- http://php.net/manual/en/function.require-once.php
Edit -- https://master.php.net/note/edit/111521
Del: integrated -- https://master.php.net/note/delete/111521/integrated
Del: useless -- https://master.php.net/note/delete/111521/useless
Del: bad code -- https://master.php.net/note/delete/111521/bad+code
Del: spam -- https://master.php.net/note/delete/111521/spam
Del: non-english -- https://master.php.net/note/delete/111521/non-english
Del: in docs -- https://master.php.net/note/delete/111521/in+docs
Del: other reasons-- https://master.php.net/note/delete/111521
Reject -- https://master.php.net/note/reject/111521
Search -- https://master.php.net/manage/user-notes.php