Am 17.06.2020 um 13:59 schrieb Benas IML <benas.molis....@gmail.com>:
> We should allow newer codebases to enforce `void` rules on
> constructors/destructors by allowing to explicitly declare return type as 
> `void`.

I don't see a big benefit in this explicit return type void as newer codebases 
hopefully will try to get rid of deprecation warnings and thus fixing it but if 
you think this is helpful then I'll shut up :-)

> Meanwhile, we should throw a deprecation warning, if the 
> constructor/destructor is
> returning a non-void value and doesn't have an explicit `: void` declaration.

I'm not sure I understand the second part "and doesn't have an explicit `: 
void` declaration".
If there is a ' : void' declaration then returning any value will be an error.
As far as I can see this is already the case:
        php -r 'class A { function __construct() : void { return 42; } }'
with PHP 7.4 gives
        PHP Fatal error: A void function must not return a value in Command 
line code on line 1

But I definitely wouldn't want a deprecation warning for constructors without 
explicit ': void' as I see no reason to force people to use it.

> Then, presumably in PHP 9, in addition to explicit `: void`, also enforce 
> `void` rules implicitly
> altogether.

Yes, that's how I would do it.

- Chris

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

Reply via email to