Can I use string concatenation to define a class CONST in PHP?

前端 未结 5 1670
一个人的身影
一个人的身影 2020-11-30 09:54

I know that you can create global constants in terms of each other using string concatenation:

define(\'FOO\', \'foo\');
define(\'BAR\', FOO.\'bar\');  
echo         


        
5条回答
  •  余生分开走
    2020-11-30 10:08

    This may not be directly what you're looking for, but I came across this thread, so here is a solution that I used for an issue I was having (based off of @user187291's answer):

    define('app_path', __DIR__ . '/../../');
    const APPLICATION_PATH = app_path;
    .
    .
    .
    require_once(APPLICATION_PATH . "some_directory/some_file.php");
    .
    .
    .
    

    Seems to work great!

提交回复
热议问题