Req #46189 [Com]: php needs a compile-time include/require like #include
| From: | nikic@php.net | Date: | Fri, 13 Apr 2012 21:23:05 +0000 |
| Subject: | Req #46189 [Com]: php needs a compile-time include/require like #include | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169567@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=46189&edit=1
ID: 46189
Comment by: nikic@php.net
Reported by: noah at missionecommerce dot com
Summary: php needs a compile-time include/require like
#include
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: Linux
PHP Version: 5.2.6
Block user comment: N
Private report: N
New Comment:
How about putting the code into a function and including it just once?
Previous Comments:
------------------------------------------------------------------------
[2008-09-27 10:12:35] noah at missionecommerce dot com
Description:
------------
Using include/require in a loop causes horrible preformance, because of the additional stat, file
read, and opt-code compile on every loop iteration.
PHP really needs a method to do compile-time includes/requires as well as the current run-time
include/require.
I would like to be able to do #include like in C and have the compiler insert the contents of the
file into the script BEFORE compilation.
This shouldn't be a complicated feature addition, and it would make life alot easier when
developing with large projects with alot of reusable code.
Reproduce code:
---------------
for( $i = 0; $i < 1000; $i ++ ) {
// I want run this code by including the file
// But this code is not appropriate to make a function for
// And its very long, so I dont just want to paste the code inside
// this loop because it makes developement more confusing
include '/www/some_code_snippet.php';
}
Expected result:
----------------
Although I knew include was a run-time event, I was hoping
behavior to #include in C.
Actual result:
--------------
Tracing the code, I found it produced 1000 file stats, 1000 file reads, and 1000 opt-code compiles
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=46189&edit=1