繁体   English   中英

php获取常量的值

[英]php get the value of a constant

我想使用“ test1”获取常量“ test”的值。

我试过了,但只得到“ test1”值,而不是“ test”值。

<?php

    class test
    {
        const test='fast';
        const test1=test;

        function testing()
        {

            echo test::test1;


        }
    }



<?php
include_once('class.test.php');

$d=new test;

echo $d->testing();

?>

有什么建议么?

使用const test1 = self::test; 定义你的常数。

以下只是一个可行的解决方案,但是您必须考虑很多事情,例如命名约定:

<?php
    class test
    {
        const test='fast';
        const test1=test;

        function testing()
        {

            echo self::test1;
            echo self::test1;

        }
    }
?>
<?php
include_once('class.test.php');    
$d=new test;    
echo $d->testing();

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM