0

I have a problem when call static property:

const LOW = 'somethg';

When I try like that it's ok: $arrv = FuzzyClass::$terms[$pk][FuzzyQuery::LOW];

But I need to use variable name and it doesn't work:

$pv = 'LOW';
$arrv = FuzzyClass::$terms[$pk][FuzzyQuery::$pv];
Anastasia S
  • 149
  • 2
  • 13

2 Answers2

1

Try this:

$arrv = FuzzyClass::$terms[$pk][constant(FuzzyQuery::$pv)];

FuzzyQuery::$pv is just a string containing LOW, thus calling that way returns low as string. Use constant identifier.

Abdul Rehman
  • 1,662
  • 3
  • 22
  • 36
0

Try to use ReflectionClass:

class FuzzyQuery {
    const LOW = 'somethg';
}

class FuzzyClass {
    public static $terms = ['index' => ['somethg' => 'Hello']];
}

$pk = 'index';
$pv = 'LOW';

$reflection = new ReflectionClass('FuzzyQuery');
$arrv = FuzzyClass::$terms[$pk][$reflection->getConstant($pv)];

echo $arrv . PHP_EOL; // Hello
Lukas Hajdu
  • 806
  • 7
  • 18