RE: [PHP-DEV] Nightmares on type hints, annotations, and aop...
| From: | François Laupretre | Date: | Wed, 18 Feb 2015 14:54:03 +0000 |
| Subject: | RE: [PHP-DEV] Nightmares on type hints, annotations, and aop... | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83074@lists.php.net to get a copy of this message | ||
Hi Bishop,
> De : bishop.bettini@gmail.com [mailto:bishop.bettini@gmail.com] De la part de Bishop Bettini
>
> THING 1: Hints are just is_* wrappers
Wrong. Only *strict* types are.
> THING 2: Hints are truthy callables
>
> function my_mixed($m) {
> return (null === $m || is_string($m));
> }
> function f(is_scalar $s, is_int $i, my_mixed $m) {};
Not sure I understand 'truthy callables'. Your example is a definition of
'strict-only' union types. It's a planned feature.
> THING 3: Pre- and post- blocks to define contracts, establish formal join
> points, with or without hints from above
Contracts are fine but cannot completely replace type hints. I initially followed this road but
reverted to thinking that both tools have their use. Contracts can implement performance-intensive
checks but, because of this, cannot be executed in production. Type hints are
performance-constrained but always executed. Another benefit of type hints is that PHP does not
provide a consistent set of 'weak' is_xxx() functions yet. Checking for an integer in PHP,
for instance, when you're ready to accept 31, 31.0, or '31', is relatively complex
and unintuitive, while 'int $arg' is readable. If is_int() did a intuitive 'PHP
way' check, contracts would be an alternative, but it is too counter-intuitive as it exists
now. And BC makes changing is_xxx() behavior impossible, of course.
> I had to get these off my chest. Forgive me their implementation ignorance.
> I am yet tired and uncaffeinated.
No problem. Every goodwill is welcome.
> To the void I commit their bodies...
Sorry, my english is too poor for that. Can you explain?
Regards
François