-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store::getId should return an int #10519
Conversation
Does it break anything? I believe there are 100500 such places, numeric strings are considered to be Recent string casting example of numeric string just because JavaScript is not so type tolerant: #10475 Also, if such change does make sense, the right place for type casting is a setter, not getter. |
Hi @orlangur, good point. The thing is, when the phpdoc says I think you cannot state that "numeric strings are considered to be int all over the code thanks to PHP loose typing" because |
So, in PHP you can use Try changing
and open any page - NOT A SINGLE Thus I don't think such kind of type casting should be introduced in some random places as it does not bring any value but breaks the things as in issue I mentioned and in a bunch of broken by this PR tests. I really like the idea of strict types and compile-time type checks though. The right way to do this is writing new code using https://wiki.php.net/rfc/scalar_type_hints_v5#strict_types_declare_directive and appropriate return type declarations (and not just PHPDocs + type casting). |
I have been mixing up languages apparently. I'm closing this one. But the strict types would indeed be very very nice. Hopefully somewhere along the road. Thanks @orlangur for being sharp. |
Hi @orlangur, <?php
declare(strict_types=1);
function myFunction(int $storeId): void
{
}
$storeId = '2'; // let's assume we executed $store->getId(); that has defined return type int
myFunction($storeId); output of
In this case you'll get type error. Why - because string !== int. BTW return type for getId method should be int|null -> something like |
Description
\Magento\Store\Model\Store::getId
should return an integer according to the phpdoc.In reality it returns strings as well.
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist