Downgrade to PHP 5.3

129 Views Asked by At

I've got a line of code that I need to get working in PHP 5.3.3. I cannot upgrade the PHP version.

The error is in the last line below with the ::class property

(unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$').

The context is:

abstract class E
{

    public static function validate($value)
    {
        $reflector = new ReflectionClass(static::class);

Is there any way to get this to work in PHP 5.3.3?

1

There are 1 best solutions below

5
Bartosz Zasada On

::class constant on classes has been introduced in PHP 5.5. The equivalent of static::class in PHP < 5.5 would be get_called_class(), so the faulty line in your code should look like this:

    $reflector = new ReflectionClass(get_called_class());