Concept
How can PHP functions be organized in separate source files?
ComputerScienceOne / Calling Functions
"40.1.2. Organizing Functions There are many coding standards that guide how PHP code should be organized. We’ll only discuss a simple mechanism here. One way to organize functions is to collect functions with similar functionality into separate PHP source files. Suppose the functions above are in a PHP source file named utils.php . We could include them in another source file (our “main” source file) using an include_once function invocation. An example: 1 <?php 2 3 include_once(\"utils.php\"); 4 5 //we can now use the functions in utils.php: 6 $p = getMonthlyPayment(1000, 0.05, 12); 7 8 ?> The include_once function loads and evaluates the given PHP source file at the point in the code in which it is invoked. The “once” in the function refers to the fact that if the source file was already included in the script/code before, it will not be included a second time. This allows you to include the same source file in multiple source files without a conflict."
Related Ideas
- How can related PHP functions be organized?ComputerScienceOne · Organizing Functions
- Where and how can functions be defined and used in PHP?ComputerScienceOne · Declaring Functions
- How do header and source files organize functions in C?ComputerScienceOne · Calling Functions
- How do you call a PHP function with values or variables?ComputerScienceOne · Organizing Functions
- How do you declare functions and specify their return values in PHP?ComputerScienceOne · Declaring Functions
- Why are functions useful in programming?ComputerScienceOne · Functions
- What are the key features of functions in PHP?ComputerScienceOne · Declaring Functions
- How can PHP libraries and math functions be used?ComputerScienceOne · PHP Tags