Concept

How can PHP default values let a constructor accept different numbers of parameters?

ComputerScienceOne / Usage

"Though we cannot define multiple constructors, we can use the default value feature of PHP functions to allow a user to call our constructor with a different number of parameters. For example,\n\n1 public function __construct($firstName, $lastName, 2 $id = 0, $gpa = 0.0) {\n\n3 $this->firstName = $firstName;\n\n4 $this->lastName = $lastName;\n\n5 $this->id = $id;\n\n6 $this->gpa = $gpa;\n\n7 }"

Related Ideas