10

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.)

  • Do you mean error_reporting level? Why don't you want use the value in php.ini or custom in php files themselves. – quanta Jul 27 '11 at 16:07
  • @quanta: Yes, I am talking about error_reporting. Sorry, it was not clear enough. I change the question now. I don't want to change it in php.ini because I use this command chain sometimes on a live server as well. And setting it in the files themselves is not an option either because I would have to set it in every file because the find command executes every file individually. And I sometimes have projects where we use external libraries and I would like to test them at the same time as well. – Raffael Luthiger Jul 27 '11 at 16:13
13

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+
  • 1
    damn... I was reading "php -h" about 10 times but somehow my mind was always jumping over this line.... Yes, this is what I was searching for. In my case I want to use: E_ALL | E_STRICT which is 32767. – Raffael Luthiger Jul 27 '11 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.