你能在函数调用中调用PHP定义的值吗?

Jas*_*vis 0 php

请看下面的示例代码,当我运行它时,在头函数调用中没有翻译定义的部分,是否有一种特殊的方法来执行语法,或者这种方法不可能吗?

<?PHP
session_start();
define('SITE_URL', 'http://testsddf.com');
$_SESSION['user_role'] = 0;


//if a user is not active, redirect to verification/suspended page
if($_SESSION['user_role'] == 0){
    header('Location: SITE_URL');
}

?>
Run Code Online (Sandbox Code Playgroud)

Pas*_*TIN 10

你做不到这样的事情:

define('SITE_URL', 'http://testsddf.com');
header('Location: SITE_URL');
Run Code Online (Sandbox Code Playgroud)

在字符串内部不插入常量:它不是变量(并且您使用单引号字符串,因此它也不适用于变量,在这里)


在这种情况下,您必须使用字符串连接:

define('SITE_URL', 'http://testsddf.com');
header('Location: ' . SITE_URL);
Run Code Online (Sandbox Code Playgroud)


并且,只是将手册的链接作为参考,你可以看看变量解析:没有关于常量的东西 - 即使这是不幸的.