ini_restore() and str_replace()

Today I’ve found a new function (new for me, that is). The function is called ini_restore(). It’s a small and simple function call, but it’s just cool to use built-in functions and save some typing and variables.

I use ini_set() from time to time in large scripts where I know it will take a while to execute and need some additional resources. I always try to avoid to set resets on the top of the script, because most of the scripts is doing regular stuff. When it would go wrong there, I want to know about it.

This is where ini_restore() comes in to play:

// old
$origMaxExecutionTime = ini_get('max_execution_time');
ini_set('max_execution_time', 900); // 15 minutes
// do some amazingly long work
ini_set('max_execution_time', $origMaxExecutionTime);

// new
ini_set('max_execution_time', 900); // 15 minutes
// do some amazingly long work
ini_restore('max_execution_time');

Aside from that one, I’ve discovered the fourth parameter in str_replace(): &$count. Nice to know whether the function call did anything or not.

Next step is to beat that annoying multibyte thing in str_replace().