5

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?

1

3 Answers 3

9

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');
1
  • 2
    So many tutorial out in the wild are teaching us to use integer as the seconds parameter, am very surprise to know that the seconds parameter is actually of type string... Sep 21, 2021 at 2:06
2

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.

2
  • Yes, I already wrapped the value. But still I don't know why it worked until now. The PHP version didn't changed... Still 7.1
    – MakoBuk
    Sep 27, 2019 at 12:29
  • @user3414654 updated the answer, to confirm your initial claim Sep 27, 2019 at 12:51
1

PHP accept the key value pair in string in PHP ini_set().

ini_set("max_execution_time", "300");
1
  • There already is an answer like this here. Could you explain what is different in your answer?
    – Dharman
    Sep 27, 2019 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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