note 62838 added to function.require-once
| From: | antoinedotpouchatmcgilldotca at osu1 dot php dot net | Date: | Fri, 10 Mar 2006 15:13:45 +0000 |
| Subject: | note 62838 added to function.require-once | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-105205@lists.php.net to get a copy of this message | ||
require_once (and include_once for that matters) is slow.
Furthermore, if you plan on using unit tests and mock objects (i.e. including mock classes before
the real ones are included in the class you want to test), it will not work as require() loads a
file and not a class.
To bypass that, and gain speed, I use :
<?php
class_exists('myClass') || require('path/to/myClass.class.php');
?>
I tried to time 100 require_once on the same file and it took the script 0.0026 seconds to run,
whereas with my method it took only 0.00054 seconds. 4 times faster ! OK, my method of testing is
quite empirical and YMMV but the bonus is the ability to use mock objects in your unit tests.
----
Server IP: 66.207.199.35
Probable Submitter: 132.216.217.210
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.require-once.php
Edit -- http://master.php.net/note/edit/62838
Del: integrated -- http://master.php.net/note/delete/62838/integrated
Del: useless -- http://master.php.net/note/delete/62838/useless
Del: bad code -- http://master.php.net/note/delete/62838/bad+code
Del: spam -- http://master.php.net/note/delete/62838/spam
Del: non-english -- http://master.php.net/note/delete/62838/non-english
Del: in docs -- http://master.php.net/note/delete/62838/in+docs
Del: other reasons-- http://master.php.net/note/delete/62838
Reject -- http://master.php.net/note/reject/62838
Search -- http://master.php.net/manage/user-notes.php