Re: Typed constants revisited
| From: | Sara Golemon | Date: | Thu, 24 Mar 2022 18:50:50 +0000 |
| Subject: | Re: Typed constants revisited | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117420@lists.php.net to get a copy of this message | ||
On Thu, Mar 24, 2022 at 10:20 AM Pierre <pierre-php@processus.org> wrote:
>
> That was exactly my point: the type could simply implicitely be the one
> of the original value.
>
>
That works when the initial value is a literal, but what about when it's
another cost?
class Foo {
const BAR = Baz::BAR;
const BLING = MY_QUX;
}
What type are Foo::BAR and Foo::BLING? Suddenly these constants have
dependent type and resolving it becomes less trivial.
Also, what happens when this code is originally written when MY_QUX is a
string, but then gets redefined (because it lives in another library we
don't control).
Allowing the author to put an explicit type removes all that uncertainty.
-Sara