1

I'm transitioning from 7.3 to PHP 8.0 (centOS) and going through the fun process of patching hordes of undefined array keys. It's easy, but time consuming. One new tool offered by PHP I hoped would offset this burden is the new Null Coalescing Assignment Operator ??= added in 7.4

https://www.php.net/manual/en/migration74.new-features.php#migration74.new-features.core.null-coalescing-assignment-operator

However, any use of this operator is throwing a parse error:

PHP Parse error:  syntax error, unexpected '=' in /home...

Example Code (based on PHP example linked above):

function foo(){
   return 'bar';
}

$array['key'] ??= foo();

Anyone run into this / know what I'm missing?

jtubre
  • 669
  • 1
  • 8
  • 13
  • 2
    Just to make sure, you're doing this on your 8.0 system, and not your 7.3 system, right? – Tim Roberts May 28 '22 at 03:36
  • Tested but no errors on PHP 7.4+ – vee May 28 '22 at 03:44
  • @TimRoberts yeah, I triple checked. First thing I thought as well. The domain I'm working in is set as 8.0 in WHM / CentOS v7.7. Going to ping this off a host admin and see if they can dig anything up. Will self-answer if I figure it out. Thanks – jtubre May 28 '22 at 18:25
  • 1
    Use [`phpversion()`](https://www.php.net/manual/en/function.phpversion.php), or `PHP_VERSION` in the code you are running to see what exactly version it is. Do not look at version number from anywhere else because it can be different. – vee May 28 '22 at 18:39

1 Answers1

0

Got it. Edge-case, but in case anyone else runs into this issue on a multiPHP server, I realized the error was only being thrown when the script was cronned. The cron job command was pointing to the general PHP binary /usr/local/bin/php.

Pointing to the specific PHP8 binary /opt/cpanel/ea-php80/root/bin/php in the command did the trick.

jtubre
  • 669
  • 1
  • 8
  • 13