Re: [RFC] Mixed type
| From: | Stanislav Malyshev | Date: | Sat, 30 Jun 2018 21:18:08 +0000 |
| Subject: | Re: [RFC] Mixed type | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102543@lists.php.net to get a copy of this message | ||
Hi!
> I would enjoy a 'mixed' typehint for exactly that reason; i.e., that I don't
> have to put it in a docblock.
I think it is exactly the opposite of what should be happening in the
language - putting things in the code which belong in the documentation,
so you don't have to write documentation. I don't think it is a good
direction.
> Given this method ...
>
> public foo(string $bar, int $baz) : void { ... }
>
> ... I don't need any docblock at all for the params.
You still do. You still need to describe what the parameters do and what
the function does.
> But given *this* method ...
>
> public foo(string $bar, int $baz, $dib) : void { ... }
>
> ... I find myself wanting (for completeness' sake) to add a docblock indicating the $dib
> typehint:
I think it's a misguided idea that the more type specifications the code
has the better is the code. "$dib" and "mixed $dib" say *exactly* the
same thing. That you do not limit what type it is. But instead of
placing it in proper place for explanatory things - namely, comments -
it places it in the code.
> public foo(string $bar, int $baz, mixed $dib) { ... }
>
> ... relieves that bit of docblock dissonance. If it does so for me, I bet it would do so for
> others.
It just means you moved some documentation into code. Which didn't make
it adequate - it's still an undocumented function - but made you feel
you don't need to document it now. I don't think it's a good thing.
--
Stas Malyshev
smalyshev@gmail.com