Re: Type variants
| From: | Michael Vostrikov | Date: | Sun, 12 Mar 2017 09:36:19 +0000 |
| Subject: | Re: Type variants | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98499@lists.php.net to get a copy of this message | ||
2017-03-12 13:58 GMT+05:00 Sherif Ramadan <theanomaly.is@gmail.com>:
> I think you're trying desperately to find a problem that is fitting of
the proposal
Checks in business logic are popular task.
> If the problem you're trying to solve pertains to object state that I
have no idea how this proposal hopes to achieve that. You can readily
control object state in PHP without the need for declarative types (e.g.
magic getters/setters)
I described in first message the way how the proposal can help with this.
There is no magic getters/setters there.
> Not seeing how this proposal improves or even achieves such a thing.
Now we need to write in business logic the following:
function checkout(Order $order)
{
if (count($order->products) > 0) {
throw new SomeException1();
}
if ($order->date === null) {
throw new SomeException2();
}
if ($order->address === null) {
throw new SomeException3();
}
// checkout steps
...
someActionWithOrderForCheckout($order);
...
}
function someActionWithOrderForCheckout(Order $order)
{
if (count($order->products) > 0) {
...
}
if ()
...
}
Of course, we can move all checks to some function like
'ensureOrderIsReadyForCheckout()' and call it everywhere manually.
But this is the same as call is_integer() manually instead of type hinting.