Suppress PHP Depreciated Messages - The Long Way

So, 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:

Code
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.ini

We 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:

Code
cd /usr/local/lib/
cp php.ini php-updated.ini


Step 2 - Edit php-updated.ini

In the new updated php-updated.ini file, we want to change 2 settings.

First, set long arrays to "Off":

Code
register_long_arrays = Off


Next, set magic quotes to "Off":

Code
magic_quotes_gpc = Off


Step 3 - Point to new php-updated.ini

Finally, 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:

Code
#!/usr/local/bin/php


to this

Code
#!/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 Way

Instead 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:

Code
#!/usr/local/bin/php


to this

Code
#!/usr/local/bin/php -n



There you go. I hope this helps someone.


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)