totothegreat
totothegreat

Reputation: 1643

Return a value from a class with a static function

I have this simple thing:

class Pkg {

    const A = 10;
    const B = 100;
    const C = 1000;

    public static function limit($pkg){
        $args = func_get_args();
        $param =  $args[0];
        return self::$param;
    }

}

And i have this in outer controller:

 $ownerPkg = 'A';
 dd(Pkg::limit($ownerPkg));

How do i get the value of A from my Pkg class?

Upvotes: 0

Views: 58

Answers (1)

wavemode
wavemode

Reputation: 2116

You can use the constant function to do this:

return constant("self::$param");

Upvotes: 1

Related Questions