DEV Community

Cover image for PHP 8 & PHP 7
Moataz khaled
Moataz khaled

Posted on

PHP 8 & PHP 7

Constructor property promotion

PHP 7

 class Point {

public float $x;
public float $y;
public float $z;

public function __construct(float $x = 0.0, float $y = 0.0, float $z = 0.0) {
    $this->x = $x;
    $this->y = $y;
    $this->z = $z;
}
Enter fullscreen mode Exit fullscreen mode

}

PHP 8

class Point {

  public function __construct(public float $x = 0.0,public float $y = 0.0,public float $z = 0.0,) {

  }

 }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)