You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setlocale's 2nd and 3rd argument ignores strict_types #18823
<?phpdeclare(strict_types=1);
try{
setlocale(LC_ALL, 0,"0"); // 2nd argument is a strict_types violation
}finally{
setlocale(LC_ALL, "0",0); // 3rd argument is a strict_types violation
}
Resulted in this output:
But I expected this output instead:
Uncaught TypeError: setlocale(): Argument #2 ($locales) must be of type string, int given in /in/dqfQT:4
Uncaught TypeError: setlocale(): Argument #3 ($rest) must be of type string, int given in /in/dqfQT:6
fwiw it seems the varargs api is currently incapable of checking types at compile time, until the varargs api is upgraded,
i think if(ZEND_ARG_USES_STRICT_TYPES()){TypeError...} is the solution for the vararg strings 🤔
i am not working on this, i was just looking for a string ...$args example in php-src for another thing. setlocale was the only such function i found, and turns out it doesn't respect strict_types, which is exactly what i was looking for: how to respect strict_types in string ...$args in C. seems the answer is ZEND_ARG_USES_STRICT_TYPES()
The second and third argument are handled in the same way (i.e. via variadics), which explains why they are both inconsistent.
An implicit conversion to string happens here:
Activity
divinity76 commentedon Jun 10, 2025
fwiw it seems the varargs api is currently incapable of checking types at compile time, until the varargs api is upgraded,
i think
if(ZEND_ARG_USES_STRICT_TYPES()){TypeError...}is the solution for the vararg strings 🤔string ...$argsexample in php-src for another thing. setlocale was the only such function i found, and turns out it doesn't respect strict_types, which is exactly what i was looking for: how to respect strict_types instring ...$argsin C. seems the answer is ZEND_ARG_USES_STRICT_TYPES()divinity76 commentedon Jun 10, 2025
probably related to #18826
ndossche commentedon Jun 10, 2025
The second and third argument are handled in the same way (i.e. via variadics), which explains why they are both inconsistent.
An implicit conversion to string happens here:
php-src/ext/standard/string.c
Line 4915 in 7f3a2bc
To fix this, a manual type check must be added in the for loop here (I think, on first sight):
php-src/ext/standard/string.c
Line 4936 in 7f3a2bc
Fix phpGH-18823: setlocale's 2nd and 3rd argument ignores strict_types
Fix phpGH-18823: setlocale's 2nd and 3rd argument ignores strict_types