note 111521 deleted from function.require-once by cmb

From: Date: Wed, 02 Sep 2015 15:20:27 +0000
Subject: note 111521 deleted from function.require-once by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203569@lists.php.net to get a copy of this message
Note Submitter: bimal at sanjaal dot com ---- 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.

« previous php.notes (#203569) next »