0

I have a client who is telling me he's experiencing the PHP parse error "Parse error: syntax error, unexpected ‘?’" in our WordPress plugin. The plugin specifies a minimum PHP version of 7.1, and includes the 'Requires" tag in the description, which should prevent the plugin from loading at all if a lower version is detected.

The function of my code uses a return with the nullable type supported in PHP 7.x

public function get_instance(): ?MyClass {
   // Do stuff here
}

He absolutely insists he is running PHP 7.4. That code should not fail. He supplied me with his WordPress Health Screen, which says PHP 7.4.22. How then could he be getting this syntax error? I've asked him to check his .htaccess to ensure there isn't a line there specifying an older PHP version. He insists not. So...I'm stumped. I've suggested he contact his host to ensure they aren't doing some funky thing behind the scenes. No reply as of this writing.

Any idea, guys? Is there something I missed or something of which I'm ignorant?

  • 1
    He should make a `phpinfo()` and check the php version there. It's not possible to help you without any informations. Perhaps he has PHP 7.4 on the CLI but not in the fpm or apache2 module. – René Höhle Aug 07 '21 at 17:26
  • It never fails, the second I ask for help I realize I'd not done the one thing I should've done. I'll ask now. Thanks! – Kevin Provance Aug 07 '21 at 17:28
  • Here's his phpinfo(); I don;t see anything to indicate a lower PHP version. https://buzzblogprotheme.com/screens/screenshot-janourah.com-2021.08.07-19_52_59.png – Kevin Provance Aug 07 '21 at 18:07
  • @KevinProvance Your function get_instance should be returning either MyClass or null, if your php version is greater than 7 – Captain Planet Aug 08 '21 at 05:15

0 Answers0