I am doing a code review and found 2 places where
ini_set('memory_limit', '512M');
is used in a function. Is this ok? Somehow it doesnt seem right to me. Is this considered bad practice?
Thanks!
There's nothing wrong with it. Consider a scenario where memory_limit
is globally set in PHP's ini file, and you want to override that setting only for one specific script/request to allow the operation to use more memory.
Calling ini_set
in a PHP script will only have the effect while PHP executes that particular request.
you could alternatively wrap this function call in another function that is called, making it so that you can change the implementation if a better way comes along in the future, or if you want to update the memory limit globally with little effort
function setMemory($limit = '512M') {
ini_set('memory_limit', $limit);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With