rfc:make_ctor_ret_void

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:make_ctor_ret_void [2020/06/17 22:25] – updated RFC moliatarfc:make_ctor_ret_void [2020/07/06 19:58] – updated RFC moliata
Line 41: Line 41:
 This RFC proposes: This RFC proposes:
   * to deprecate the ability of returning values from constructors and destructors in PHP 8.0.   * to deprecate the ability of returning values from constructors and destructors in PHP 8.0.
-  * to treat both contructors and destructors that do not have an explicit return type, as if they have a return type of ''void'' in PHP 9.0. +  * to treat both constructors and destructors that do not have an explicit return type, as if they have a return type of ''void'' in PHP 9.0. 
-  * to allow explicit ''void'' return type on constructors and destructors.+  * to allow explicit ''void'' return type on constructors and destructors (secondary vote).
  
 A deprecation warning would be generated: A deprecation warning would be generated:
-  * for any constructor or destructor that returns a value (PHP 8.0).+  * for any constructor or destructor that returns a value in PHP 8.0 
 + 
 +Note: if there is an explicit ''void'' return type, a fatal error will be generated instead. This allows for newer codebases to take advantage of the check in PHP 8.0 already.
  
 A fatal error would be generated: A fatal error would be generated:
-  * for any constructor or destructor that returns a value (PHP 9.0)+  * for any constructor or destructor that returns a value in PHP 9.0. 
-  * for any constructor or destructor that has an explicit return type other than ''void''.+  * for any constructor or destructor that has an explicit return type other than ''void'' (secondary vote).
  
 <code php> <code php>
Line 59: Line 61:
  }  }
  
- // this is illegal+ // this is also illegal
  public function __destruct(): mixed {}  public function __destruct(): mixed {}
 } }
  
 class Test2 { class Test2 {
- // this is legal+ // this is legal (secondary vote)
  public function __construct(): void {}  public function __construct(): void {}
  
Line 72: Line 74:
 </code> </code>
  
-===== Backward Incompatible Changes =====+===== Backwards incompatible changes =====
 Accepting this RFC results in a small backwards compatibility break in PHP 9.0 since it will no longer be legal to return (''mixed'' and any of its subtypes) values from constructors and destructors. Accepting this RFC results in a small backwards compatibility break in PHP 9.0 since it will no longer be legal to return (''mixed'' and any of its subtypes) values from constructors and destructors.
  
-The position of this RFC is that this BC break is minimal, as returning values from contructors/destructors is not a standard pattern used by many pieces of code. However, to minimize the number of BC breaks even further, the ability of returning values from constructors/destructors is deprecated in PHP 8.0.+The position of this RFC is that this BC break is minimal, as returning values from constructors/destructors is not a standard pattern used by many pieces of code. However, to minimize the number of BC breaks even further, the ability of returning values from constructors/destructors is deprecated in PHP 8.0.
  
-===== Unaffected Functionality =====+===== Unaffected functionality =====
 ==== Explicit return type declaration is optional ==== ==== Explicit return type declaration is optional ====
 Explicitly declaring the return type declaration would be optional. It would still be allowed to not specify a type at all: Explicitly declaring the return type declaration would be optional. It would still be allowed to not specify a type at all:
Line 109: Line 111:
  
 ===== Vote ===== ===== Vote =====
-2/3 majority Yes/No.+Primary: Make constructors and destructors return void? Yes/no. 
 + 
 +Secondary: Allow void return type on constructors/destructors? Yes/no.
  
 ===== Implementation ===== ===== Implementation =====
 [[https://github.com/php/php-src/pull/5727|GitHub Pull Request]] [[https://github.com/php/php-src/pull/5727|GitHub Pull Request]]
rfc/make_ctor_ret_void.txt · Last modified: 2020/07/22 15:29 by moliata