[php-src] Issue #8420: Cutting off an empty body of a function
| From: | roxblnfk | Date: | Thu, 21 Apr 2022 14:46:12 +0000 |
| Subject: | [php-src] Issue #8420: Cutting off an empty body of a function | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241131@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8420
Author: roxblnfk
### Description
## Introduction
Since PHP 8.0 we have the [Constructor Property
Promotion](https://wiki.php.net/rfc/constructor_promotion) feature.
Often, using this feature, we get a constructor with an empty body:
```php
class Point {
public function __construct(
public float $x = 0.0,
public float $y = 0.0,
public float $z = 0.0,
) {
}
}
```
## Proposal
Add the ability to replace an empty function body with a semicolon:
```php
class Point {
public function __construct(
public float $x = 0.0,
public float $y = 0.0,
public float $z = 0.0,
);
}
```
In the first iteration it might be limited to a constructor and methods with the
void
returning type.
## Future scope
In the case of the proposed feature and [this RFC (Add true
type)](https://wiki.php.net/rfc/true-type) implementation, we can talk about the possibility of such
a syntax sugar:
```php
interface User {
function isAdmin(): bool;
function getFoo(): ?Foo;
}
class Admin implemets User
{
function isAdmin(): true
{
return true;
}
/** @link https://wiki.php.net/rfc/null-false-standalone-types
Allow null and false as stand-alone types **/
function getFoo(): null
{
return null;
}
}
// can be replaced with
class Admin extends User
{
function isAdmin(): true;
function getFoo(): null;
}
```
## Implementation
Sorry, i can not create a PR with the feature i but can help with test cases