Hello PHPeeps!
Recent events convinced me to write this RFC :P
Please have a read here https://wiki.php.net/rfc/allow-void-variance
I am targeting all the supported PHP versions because this is mainly to
placate the discontent that arised by PHPUnit enforcing its users to use
void, so waiting 7.4 doesn't make much sense.
FTR this is an improvement regardless of PHPUnit, and it's IMO a very
reasonable change.
Thank you for your time.
Wes
Le 4 févr. 2019 à 04:22, Wes netmo.php@gmail.com a écrit :
Hello PHPeeps!
Recent events convinced me to write this RFC :P
Please have a read here https://wiki.php.net/rfc/allow-void-variance
I am targeting all the supported PHP versions because this is mainly to
placate the discontent that arised by PHPUnit enforcing its users to use
void, so waiting 7.4 doesn't make much sense.FTR this is an improvement regardless of PHPUnit, and it's IMO a very
reasonable change.Thank you for your time.
Wes
The RFC says: “Changing from void to something else is very probably a bad idea, but PHP should not enforce void in subclasses just on that basis.” — If it is “very probably” a bad idea, why do people want to do that? What are the use cases? (Sorry, I’ve not followed the “recent events” you alludes to.)
—Claude
Hi!
PHPUnit 8 changed e.g. function setUp(){}
to function setUp(): void{}
and a lot of people did not like being forced to do the same on
their setUp()
.
The issue is not PHPUnit adding void
, but PHP forcing void
even when
it's not necessary. If PHPUnit wants to use void but inheritors don't want
to, it should just be possible.
"probably a bad idea" is opinionated, in reality there is no provable
reason to disallow it, from a pure type-theory standpoint.
Isn't this "fixed" with the Covariance/Contravariance RFC which has been
voted recently
George P. Banyard
Hi!
PHPUnit 8 changed e.g.
function setUp(){}
tofunction setUp(): void{}
and a lot of people did not like being forced to do the same on
theirsetUp()
.The issue is not PHPUnit adding
void
, but PHP forcingvoid
even when
it's not necessary. If PHPUnit wants to use void but inheritors don't want
to, it should just be possible."probably a bad idea" is opinionated, in reality there is no provable
reason to disallow it, from a pure type-theory standpoint.
Nope, it's not. https://3v4l.org/N4LNb It should've been fixed.
Indeed, many people expected it to work already.
This is normal the Covariance/Contravariance is coming in PHP 7.4 not
before.
This RFC would also target PHP 7.4 so I don't see how this RFC would change
the PHPUnit problem.
George P. Banyard
Nope, it's not. https://3v4l.org/N4LNb It should've been fixed.
Indeed, many people expected it to work already.
Covariance from no-type is already supported, since 7.0
https://3v4l.org/I1hZs
I know this, I am talking about this RFC
https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters
Which has been voted and implementation is being worked on a GitHub PR:
https://github.com/php/php-src/pull/3732
Your proposal doesn't bring anything new to the table that this RFC does.
Moreover, your RFC targets the same PHP version as the
covariant/contravariant RFC.
So like said before the issue which your RFC tries to address is already
being fixed.
Also, there is no need to upgrade to PHPUnit 8 and if people want to there
is a PHP_CS_FIXER sniff which can add void return types.
Namely: void_return
George P. Banyard
Covariance from no-type is already supported, since 7.0
https://3v4l.org/I1hZs
I know this too. I am often in touch with Levi and void variance is not
covered by his RFC
As a matter of fact, if you try to compile that PR void will behave exactly
like it does now
My RFC targets 7.2 and 7.3 other than 7.4
I know this too. I am often in touch with Levi and void variance is not
covered by his RFC
As a matter of fact, if you try to compile that PR void will behave exactly
like it does now
First of all, apologies as I needed a brush up on the difference between
general variance and covariance.
In fact, the RFC linked does not cover the variance of the void type.
My RFC targets 7.2 and 7.3 other than 7.4
Secondly, I am nearly certain, but I would love to be proven wrong, that
new features aren't backported to older PHP releases.
So even then I don't think this will land in PHP 7.2/7.3
Now back to the proposal of the variance of void type.
I'm not sure I see the point of it?
Let me explain: if I define a method as void it means that it does stuff
which doesn't/can't return a sensible value.
Also, I am defining behavior and changing the return type, at least to me,
is a change in behavior.
Because a function/method which clearly is not intended to be used as a
value can now under your proposal become one.
Sure you can say that the return value may be only used by the child class
but if I want to change my parent class to this child class
I can't be sure that it will behave as before because maybe the child
class needs the return value of this previously void method.
Maybe I am just overthinking this however in my opinion if a return type
needs to be changed from void to something you are trying to
add behavior to a method which probably should go into its own method.
Best regards
George P. Banyard
Hi!
Recent events convinced me to write this RFC :P
Please have a read here https://wiki.php.net/rfc/allow-void-variance
I am targeting all the supported PHP versions because this is mainly to
placate the discontent that arised by PHPUnit enforcing its users to use
void, so waiting 7.4 doesn't make much sense.
I was never a big fan of void pseudotype, but since it exists, I think
it makes sense to be able to override it. It does not violate the
protocol (since it's impossible in PHP for function to not return a
value, and it's very implausible anybody relies on void function to
return null). And since we have users complaining, it makes sense to fix it.
--
Stas Malyshev
smalyshev@gmail.com
Hi Wes
Den man. 4. feb. 2019 kl. 05.19 skrev Wes netmo.php@gmail.com:
Hello PHPeeps!
Recent events convinced me to write this RFC :P
Please have a read here https://wiki.php.net/rfc/allow-void-variance
I am targeting all the supported PHP versions because this is mainly to
placate the discontent that arised by PHPUnit enforcing its users to use
void, so waiting 7.4 doesn't make much sense.
I don't like to suddenly change things like that in lower versions. I
would be for it for 7.4, but not merging to already active releases
branches. That is usually not how we deal with things like this.
--
regards,
Kalle Sommer Nielsen
kalle@php.net