Jump to content
NotionCommotion

Weak type declaration for integers

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites

I see now.  I only experience the issue when the file includes declare(strict_types=1) which is what it should do.  Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.