shlogg · Early preview
David Duymelinck @xwero

PHP 8.0 Named Parameters Simplify Code

PHP 8.0 introduces named parameters, making functions & class methods easier to use, less error-prone & self-documenting. Named params can be skipped if they have default values, e.g. `a(b: 'b', d: true)`.

Attributes
First class callable syntax
Constructor changes

As promised in my last post this one is about parameters

  
  
  Theory

The biggest change is named parameters in php 8.0. This makes functions and class methods easier to use, less error prone and makes calling them self documenting.
A little change in php 8.0 is that you can add a comma after the last parameter. This is made because then you can follow the convention that is used for multi-line arrays.

  
  
  Code


function a($b, $c = 1, $d = false,) {
  var_dump($b, $c, $d);
}

    
    

    
    




Since php 5.6 you can do...