0

我想使用“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();

?>

有什么建议么?

4

2 回答 2

2

用于const test1 = self::test;定义常量。

于 2014-10-24T07:24:05.027 回答
0

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

<?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();

?>
于 2014-10-24T07:25:41.800 回答