Pavan
Pavan

Reputation: 13

php get the value of a constant

I want to get the value of a constant "test" using "test1".

I have tried it but only getting "test1" value but not "test" value.

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

?>

Any suggestions?

Upvotes: 0

Views: 104

Answers (2)

user3522371
user3522371

Reputation:

Below is just a working solution, but you have to consider about lot of things such as naming conventions:

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

?>

Upvotes: 0

zessx
zessx

Reputation: 68790

Use const test1 = self::test; to define your constant.

Upvotes: 2

Related Questions