-1

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?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Gumby
  • 9

1 Answers1

0

::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());
Bartosz Zasada
  • 3,762
  • 2
  • 19
  • 25
  • So, relatedly this code gives unexpected T_OBJECT_OPERATOR error. Is there a similar fix? $request['order'] = $this->maybeSetKey($request['order'], 'date_time_created', (new \DateTime($builder->getOrderCreateDate()))->format(\DateTime::RFC3339_EXTENDED)); – Gumby Jun 02 '20 at 14:47
  • Is that line in the same method? There's no `$this` in static methods. You'll have to make `maybeSetKey` static and call it with `self::maybeSetKey()`. – Bartosz Zasada Jun 02 '20 at 14:52
  • No, different method. I'm seeing this code for the first time (not mine). – Gumby Jun 02 '20 at 16:40
  • I don't know then. There's an excellent post on SO that helps solve parse errors: https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them. Since I helped you with the original problem, please mark my answer as accepted. – Bartosz Zasada Jun 03 '20 at 05:11
  • I am trying, but since I am new it says it records it but doesn't show it(?) – Gumby Jun 04 '20 at 12:02