Setting php error_reporting value with a console parameter

14,157

According to php -h

-d foo[=bar]     Define INI entry foo with value 'bar'

If you want the recommended production default (E_ALL & ~E_DEPRECATED), the value would be 22527 in PHP 5.3, and 24575 in PHP 5.4+.

php -l -d error_reporting=22527

Finding the value for various combinations is simple.

php -r 'echo E_ALL & ~E_NOTICE | E_STRICT;' # should return 32759
php -r 'echo E_ALL & ~E_DEPRECATED;' # should return 22527 in PHP 5.3, 24575 in PHP 5.4+
Share:
14,157

Related videos on Youtube

user1233802
Author by

user1233802

server administrator and web application developer.

Updated on September 18, 2022

Comments

  • user1233802
    user1233802 over 1 year

    In order to test my PHP projects on errors I normally use this command:

    find ./ -type f -name \*.php -exec php -l '{}' \; | grep -v "No syntax errors detected"
    

    I would like to extend the part php -l '{}' \; with some parameters so it will use a custom error_reporting level and not the one defined in php.ini. Is this possible?

    (I know that the question is somewhat coding related. On the other side it is more about shell commands. If you think it should be better on stackoverflow then feel free to move it. I was not sure where the question fits better.)

    • Greg Petersen
      Greg Petersen almost 13 years
      Do you mean error_reporting level? Why don't you want use the value in php.ini or custom in php files themselves.
  • Martin Prikryl
    Martin Prikryl about 4 years
    Since PHP 5.4, E_STRICT is a part of E_ALL. And E_ALL has a handy shortcut value -1. So one can do php -d error_reporting=-1 to enable all reporting.