shlogg · Early preview
David Duymelinck @xwero

Php 8 Constructor Property Promotion Simplified Class Creation

Php 8.0's constructor property promotion simplifies class creation by reducing repetition. New in initializers allow nested attributes, making code less error-prone and IDE-friendly.

After attributes and first-class callable syntax I got the idea to bundle the method parameter improvements.

  
  
  Theory

Php 8.0 constructor property promotion. 
Php 8.1 introduced new in initializers.
Constructor property promotion makes it easier to create classes without repetition. While new in initializers is more geared to attributes, specifically to allow nested attributes 
  
  
  Code


class A{
   function __constructor(public string $b, private $c = new C()) {}
}

    
    

    
    



Before you had to write it like this

class A {
  public string $b;
  private $c;
   functi...