Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does function definition order matter?

In the script below, does the order in which items are declared matter?

For example, if the add_action points to a function that has not yet been defined? Does it matter or should the function declaration always precede any code in which its called?

add_action('load-categories.php', 'my_admin_init'); function my_admin_init(){ //do something } 
like image 631
Scott B Avatar asked Mar 29 '11 04:03

Scott B


People also ask

Does the order of a function matter?

Name of Property: The Order Of Parameters in a Function Does Not Matter.

Does function definition order matter in Python?

So in general, yes, the order does matter; there's no hoisting of names in Python like there is in other languages (e.g JavaScript).

Does the order of function declaration matter in C?

The order of functions inside a file is arbitrary. It does not matter if you put function one at the top of the file and function two at the bottom, or vice versa. Caveat: In order for one function to "see" (use) another function, the "prototype" of the function must be seen in the file before the usage.

Do functions have to be in order C++?

Please clarify the issue. Functions should at least be declared before being used. But once you declared them, the order does not matter (or very marginally). For short functions, it might be slightly better to group related functions (eg f before g if g calls f ), perhaps because of cache issues.


1 Answers

That doesn't matter if the function is declared before or after the call but the function should be there in the script and should be loaded in.

This is the first method and it will work:

some_func($a,$b);  function some_func($a,$b) {     echo 'Called'; } 

This is the second method and will also work:

function some_func($a,$b) {     echo 'Called'; }  some_func($a,$b); 
like image 55
Shakti Singh Avatar answered Sep 17 '22 23:09

Shakti Singh