What’s the purpose of ini_set() in php? (especially for error reporting)

Ok so PHP has the function ini_set() which a lot of people are aware of and will use to set various configuration options (here) to help with development etc. However, this function does only seem to work at runtime and will not work if there are any fatal errors or the script has syntax errors and can’t be parsed / compiled.

Therefore surely there is no point of doing this (from the manual):

http://php.net/manual/en/function.ini-set.php

Examples

Example #1 Setting an ini option

<?php
echo ini_get('display_errors');

if (!ini_get('display_errors')) {
    ini_set('display_errors', '1');
}

echo ini_get('display_errors');
?>

I don’t know if I’m just missing something and my php.ini isn’t configured correctly, but a lot of the time I get no errors. For beginners / juniors there will no doubt be a lot of syntax errors (missing semi-colons, closing brackets etc), and said juniors would search for how to turn on errors, assume the above manual entry is correct, yet when re-running their script, alas, they get no errors as the script cannot be parsed / compiled in the first place.

I know you can set display_errors = On in the php.ini file and restart your web server to show all errors to the screen (using this in a development environment, definitely not live), but wouldn’t it be better just to remove the function and only configure the php.ini file for different error levels?

Update:

I know ini_set isn’t just for displaying errors, but code can’t be very manageable if you’re calling ini_set in certain scripts / functions / files and wouldn’t it make more sense to use the php.ini for something like that?

Update

So the ini file can be used to set global configuration options, surely you’d use this for security or optimisation, however developers could still use ini_set to override some of these options at runtime which may not be desirable

In summary (@Hanky웃Panky):

Why do I have the option of displaying errors when some trivial syntax errors will still not display?

Leave a Comment

error code: 523