Suppress PHP Depreciated Messages - The Long WaySo, you're running your PHP CLI program on a newer version of PHP (like 3.5.10) and you are getting these annoying lines at the top of your output:
PHP Deprecated: Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in Unknown on line 0
PHP Deprecated: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0
This is caused by 2 depreciated features of PHP that are set to "On" in your php.ini file.
Here's how you suppress these messages without changing your php.ini file or affecting any other PHP scripts on your system.
Step 1 - Copy php.iniWe need to create a copy of our existing php.ini file that has a couple settings changed. We don't want to change anything in our original php.ini however because we don't want to break any existing applications.
First, make a copy of your existing php.ini and name it something different:
cd /usr/local/lib/
cp php.ini php-updated.ini
Step 2 - Edit php-updated.iniIn the new updated php-updated.ini file, we want to change 2 settings.
First, set long arrays to "Off":
register_long_arrays = Off
Next, set magic quotes to "Off":
Step 3 - Point to new php-updated.iniFinally, we need to tell php to use our NEW php configuration file instead of our old one. We'll use the -c option to do this.
In our PHP CLI program, on the shebang line (the very first line), change this:
to this
#!/usr/local/bin/php -c /usr/local/lib/php-updated.ini
That's it.
Those 2 pesky messages should now be gone.Suppress PHP Depreciated Messages - The Short WayInstead of going through all the trouble above, you may consider just ignoring the php.ini file altogether. Usually this should be fine, but in certain circumstances, php may not act the way you want and so you'll have to resort to using the first method ("The Long Way") above.
This only requires 1 step. We're going to alter the shebang line to tell PHP to ignore your php.ini file and just use all default settings.
Change your shebang line from this:
to this
There you go. I hope this helps someone.