Follow

Just a quick rough-up of a proposal idea by @beausimensen@twitter.com for static return type hints in PHP.

Description:
gist.github.com/simensen/729c4

Implementation:
github.com/php/php-src/compare

There's probably a little extra work to be done to ensure covariance rules are respected, but this is a place to start discussion.

@pollita wow. Neat diff you made there. That took a surprisingly small amount of changes 😁

@johmanx10 Yeah, I was pleasantly surprised by how much of the work was already done. Could roll static as a param type hint as well, but I legit have zero idea what that would buy anyone.

@pollita nah, sounds like introducing a world of hurt. The only use case I see there is if you want to have an equals method for value objects put in a trait. Does that even work, given that you get class composition with traits? In other cases, you can solve this with covariance, I'm sure.

@johmanx10 Yeah, that's what I'm saying. Every use-case I try to imagine ends up looking like something we can already do in a different way. /shrug

Sign in to participate in the conversation
PHP Community on Mastodon

Open source. Open community. We are dedicated to building and enriching the PHP community.