php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46189 php needs a compile-time include/require like #include
Submitted: 2008-09-27 10:12 UTC Modified: 2012-04-13 23:12 UTC
From: noah at missionecommerce dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: noah at missionecommerce dot com
New email:
PHP Version: OS:

 

 [2008-09-27 10:12 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-13 21:23 UTC] nikic@php.net
How about putting the code into a function and including it just once?
 [2012-04-13 21:50 UTC] johannes@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2012-04-13 21:50 UTC] johannes@php.net
As a historic remark: We had such behavior in PHP 3, where include was run-time, and require compile-time. We got rid of it intentionally. Use functions or other structures to solve your issue.
 [2012-04-13 23:12 UTC] rasmus@php.net
Yes, wrap your stuff in a function, or use an opcode cache and all the stats and 
compiles go away.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 02 08:01:28 2025 UTC