Hello everyone.

My name is Wendell Adriel, I work with PHP since 2009 and these last couple of 
days I was thinking that we have made HUGE progress with types on PHP so far.

We can add types in a lot of places, but we still don't have a way to add types 
to inline variables.



The Idea



I was talking about this on Twitter with some developers and I wanted to check 
how's the feeling on this.

I know that there's a draft RFC that mentions this in the Future Scope section: 
https://wiki.php.net/rfc/declare_vars

But my idea is not to have the declaration of variables like that. I'm thinking 
on a straightforward implementation that would be like:



Today we have:



$value = 10;

$value = 'foo'; // OK



My proposal is to be able to do something like:



int $value = 10;

$value = 'foo'; // TypeError



This typing would be optional and under the hood all current declarations would 
implicitly add the mixed type to the variable.

So this:



$value = 10;



Would be interpreted as:



mixed $value = 10;



-----



Implementation



I'm new to the PHP source code, but I'm looking into it and studying so I can 
be able to work on the implementation and not only in creating/proposing the 
RFC.

If someone that has more experience wants to help me it would be great.



-----



I'm happy to help with anything needed for this to happen and if someone wants 
to discuss further just ping me.

Thanks in advance for the attention.



---

Best Regards,

Wendell Adriel.

Software Engineer | Investor | Amateur Photographer | Musician | INFP​


https://wendelladriel.com

Reply via email to