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 }
Name of Property: The Order Of Parameters in a Function Does Not Matter.
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).
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With