New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable can be final #363
Comments
I think we shouldn't go into meta-programming and wait for the corresponding RFC instead. |
I don't found any RFC about final variables. |
Introduction of Hungarian notation is not a good idea. I also think that there is no RFC as it would be very hard to implement this in PHP due to the way arrays are implemented, this also stopped the work on the immutable data class RFC. That being said, an annotation could be used: /**
* @final
* @var int
*/
$num = 42; |
I don't like annotations like that (phpdoc). Unfortunatelly PHP internals doesn't accepts the @final $num = 42; I really don't understand. I guess that is a conflict with the silence operator. The reason for the Hungarian notation is to avoid the phpdoc. But it could be done together, depending of preference of developer. |
There were no RFC yet for final variables, but I think we are going to see such RFC in near future =) |
Annotations where discussed ad infinitum but no conclusion could be found, too many opinions and hard to implement. Are you creating one @kalessil? |
For the time being, I give +1 to annotations. I also think Hungarian notation will make no good. PHP has more type safety now. As @kalessil said RFC for this, as well as for real Polymorphismus or others related to typing should not be far away. @Fleshgrinder with:
did you mean this one? https://wiki.php.net/rfc/immutability, if not, can you share the link? With annotations, something like:
Adds more code that sometimes just look ugly to see even in a local variable usage; but compromise should be made if is desired such checking in code. Regarding what annotation to use I really don't have any idea what to use, |
@davidmpaz that's exactly the one I referred to, yes. |
@Fleshgrinder: nope =) |
It is a big confuse, once that PHP don't have support to
final
modifier, but we can implement that by creating some king of "variable annotation". Then I think about prefix a variable with$f
to identify that it is final and should not be overrided.It should works like we did with parameters, by prefixing it by
$pName
.The text was updated successfully, but these errors were encountered: