Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Wow, interesting:

"Whether or not the function being called was declared in a file that uses strict or weak type checking is irrelevant. The type checking mode depends on the file where the function is called."

That means that my function can have a parameter defined as an int in its strict file, but if it's called from outside of it, anything can still be passed to that parameter, right?

I'm not sure how I like that. What if you're passing input from class A into class BStrict then using BStrict to call a function in CStrict? BStrict and CStrict are defined as strict, where A is not. Would BStrict then be the one throwing the error because the "caller" is the issue?

From the description it seems that the parameters are effectively ignored in BStrict when A calls it.

Am I missing something or does this sound iffy?

Edit: Link for quote - https://wiki.php.net/rfc/scalar_type_hints_v5#parameter_type...



> That means that my function can have a parameter defined as an int in its strict file, but if it's called from outside of it, anything can still be passed to that parameter, right?

Not at all. It's "weak" typing, not no typing.

A small set of convertible values can be passed and will be converted to the type you asked for, while other values error as usual.

See the rest of the RFC.


You're right, I see that now. That's why they went into describing type conversions too. Thanks for the insight!


Sounds right to me. If you're using untyped code, you shouldn't care what you're calling into. strict mode should only apply when both parties agree to it, otherwise strict mode would be the default and you'd have to explicitly mark code as unstrict.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: