NotionCommotion Posted March 11, 2019 Share Posted March 11, 2019 Is it possible to perform type declaration which allows either an integer or a string digit (i.e. ctype-digit) instead of the following? function someFunction(int $id){} Looking at functions.arguments.type-declaration, I expect not. If not, would you recommend type casting before calling the function or removing type declaration from the function and performing the check manually within the function and throwing an applicable exception? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/308449-weak-type-declaration-for-integers/ Share on other sites More sharing options...
requinix Posted March 11, 2019 Share Posted March 11, 2019 You have to scroll down to the Strict Typing section to see that PHP will coerce by default. So the "int" hint does what you want. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308449-weak-type-declaration-for-integers/#findComment-1565170 Share on other sites More sharing options...
NotionCommotion Posted March 11, 2019 Author Share Posted March 11, 2019 I see now. I only experience the issue when the file includes declare(strict_types=1) which is what it should do. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/308449-weak-type-declaration-for-integers/#findComment-1565171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.