• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Turn off PHP warnings from Command Line?

Paul Larson

Basic Pleskian
Server operating system version
CentOS Linux release 7.9.2009
Plesk version and microupdate number
Obsidian 18.0.46
This is probably a Centos Question, but I've noticed more verbose warning output since upgrading a site to PHP 8.1, e.g.

Code:
-bash-4.2$ php myscript.php
The following error occurred:
E_DEPRECATED: explode(): Passing null to parameter #2 ($string) of type string is deprecated

Centos Version:

Code:
-bash-4.2$ cat /etc/*rel*
CentOS Linux release 7.9.2009 (Core)
Derived from Red Hat Enterprise Linux 7.9 (Source)

Code:
-bash-4.2$ php -v
PHP 8.1.14 (cli) (built: Jan  9 2023 10:16:54) (NTS)

I get the same output when I use an absolute path:

Code:
-bash-4.2$ /opt/plesk/php/8.1/bin/php myscript.php
The following error occurred:
E_DEPRECATED: explode(): Passing null to parameter #2 ($string) of type string is deprecated
 
It's not a OS related issue, nor is it an Plesk related issue. It is merely a PHP issue.

It also the correct behavior for PHP 8.1 as passing null to non-nullable parameters of built-in functions will result in a deprecation notice. Even tough it is just a notification and not an actual error, the obvious solution would be to fix the issue in your code. Making it future proof for PHP version where passing null to non-nullable parameters are actually deprecated and will cause an error.

If that's not what your after then you can suppress deprecation notices by removing E_DEPRECATED from the error_reporting value on the PHP settings page of your domain in Plesk (or in the PHP settings tab of your service plan if want to get rid of the deprecation notices for all of your domains). Or instead add the error_reporting() function to your script.

There is no way to only suppress the deprecation notices on command line only. It's all or nothing.
 
Last edited:
Back
Top