define my own BASE_PATH vs. set_include_path?

后端 未结 2 1918
春和景丽
春和景丽 2021-02-20 16:21

I learned of the function set_include_path(). All this time, I defined a constant in the config.php file

define(\'BASE_PATH\', \'/var/www/mywebsite/public_html/         


        
2条回答
  •  猫巷女王i
    2021-02-20 16:37

    I think Micahel's explanation is very clear.

    I recommended you to use "set_include_path" when you store all your PHP files in an folder, for example: "libs/" (its easier). Using the define() method should be faster as you are specifying the file path explicitly.

    Always try to avoid to use absolute paths unless they are really necessary. I found very useful to specify your paths this way:

    define("BASE_PATH", dirname(__FILE__));
    

    This way you will avoid to have to update the path each time you move the code.

提交回复
热议问题