Home >Backend Development >PHP Tutorial >如果把变量作为常量的名称?

如果把变量作为常量的名称?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:47:341384browse

define('DBNAME','test');
$val = 'DBNAME';
echo eval($val);

回复内容:

define('DBNAME','test');
$val = 'DBNAME';
echo eval($val);

火速解答

eval是安全性最差的实践,几乎没有之一。请永远不要使用eval

使用字符串作为名称请求常量的值,请直接用constant函数。

define("MAXSIZE", 100);
echo MAXSIZE;
echo constant("MAXSIZE"); // same thing as the previous line
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn