Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - ini_set() expects parameter 2 to be string, integer given

I have this part of code:

...
ini_set('max_execution_time', 300);
...

Until now it worked. Now i am getting this error:

ini_set() expects parameter 2 to be string, integer given

What has changed? Can it be caused by PHP version?

like image 284
MakoBuk Avatar asked Sep 27 '19 12:09

MakoBuk


2 Answers

PHP actually expects both parameters of ini_set() to be of type string and returns a string:

ini_set ( string $varname , string $newvalue ) : string

You can find this in the PHP manual on ini_set.

If you have set strict_types with

declare(strict_types=1);

then you will have to change your ini_set() values to

ini_set('max_execution_time', '300');
like image 155
digijay Avatar answered Oct 16 '22 03:10

digijay


Not sure how it was working for you. Here is the reference. Second parameter needs to be string data type.

Maybe you was using a variable to set it until now and that variable was somehow getting casted to string? not sure.

Anyways, just use string instead of an integer as second parameter:

ini_set('max_execution_time', '300');

and you should be good.

Weird enough, just now i noticed, giving second parameter as integer is working on my Server.

Also Here, if you search with "ini_set", the example is given with second parameter as integer:

ini_set('assert.exception', 1);

It is weird why its not working for you.

like image 23
Abhay Maurya Avatar answered Oct 16 '22 03:10

Abhay Maurya