function f(int $value){
    $value="foo"; // should this be a TypeError? BC break all the things
}

On Mon, 6 Feb 2023 at 22:15, someniatko <somenia...@gmail.com> wrote:
>
> Hi there,
>
> I am not a core PHP language developer, just a regular PHP programmer, and
> cannot speak for the whole community, so I'll just share my opinion.
>
> I believe a new language feature suggestion should contain not only its
> description, but also motivation: i.e. what are we trying to achieve with
> it. Will the development experience be worse without it, or maybe it
> disallows some sneaky bugs to appear in your code, or maybe it acts as a
> native documentation for your code etc.
>
> Personally it's hard for me to see what kind of improvement will
> restricting a type of a variable bring. It may prevent repurposing the
> variable with the same name for a different use somewhere down the
> function, which can lead to bugs if a function is large enough. However,
> for such cases I think better idea would be to introduce `const` variables
> like in JavaScript - which can only be set once and cannot be reassigned
> later. This way you'll also guarantee the type of the variable will be
> preserved.
>
> > We can add types in a lot of places, but we still don't have a way to add
> types to inline variables.
>
> > int $value = 10;
> > $value = 'foo'; // TypeError
>
> Can you describe some use cases where this feature will be useful? I see
> it's coming from statically typed / compiled languages like C++, but in
> such languages compiler must know variable type in order to manage memory
> properly. As PHP is an interpreted  language, it doesn't have this problem.
>
> Regards,
> Illia / someniatko

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to