Does function definition order matter?

前端 未结 7 1800
滥情空心
滥情空心 2021-01-17 07:33

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 ma

7条回答
  •  一向
    一向 (楼主)
    2021-01-17 07:59

    From the PHP manual:

    Functions need not be defined before they are referenced, except when a function is conditionally defined as shown in the two examples below.

    However, while this is more of a personal preference, I would highly recommend including all the functions you actually use in an external functions.php file then using a require_once() or include_once() (depending on tastes) at the very top of your main PHP file. This makes more logical sense -- if someone else is reading your code, it is blindingly obvious that you are using custom functions and they are located in functions.php. Saves a lot of guesswork IMO.

提交回复
热议问题