Bifalgorithm post · Computer science one · Calling Functions

How can PHP functions be organized in separate source files?

How can PHP functions be organized in separate source files? (Computer science one · Calling Functions) — "40.1.2. Organizing Functions There are many coding s…

Ideas in this flowchart

  • Organiser les fonctions dans un programme PHP
  • Les standards de codage guident l’organisation du code PHP.
  • Le mécanisme présenté consiste à regrouper les fonctions similaires.
  • Les fonctions ayant une fonctionnalité similaire sont placées dans des fichiers PHP séparés.
  • Les fonctions peuvent être regroupées dans un fichier nommé utils.php.
  • Le fichier principal inclut utils.php avec un appel à include_once.
  • include_once charge et évalue le fichier PHP à l’endroit où l’appel est effectué.
  • Si le fichier a déjà été inclus auparavant, il n’est pas inclus une seconde fois.
  • Cette règle évite les inclusions répétées du même fichier.
  • Le même fichier source peut être inclus dans plusieurs fichiers sans créer de conflit.
  • Après l’inclusion, les fonctions de utils.php peuvent être utilisées, par exemple getMonthlyPayment.
Feed/

How can PHP functions be organized in separate source files?

No cover

Channel

Computer science one

1 page

"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."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.