<?php
function Test(?string $name=null, ?int $age=null){
$name= $name??"Guest";
$age=$age??0;
echo "Hello my name is $name my age is $age \n";
}
Test(age:44, name:"Ambiorix");
?>
Output:
9 ms | 18.4 MBHello my name is Ambiorix my age is 44
<?php
function Test(?string $name=null, ?int $age=null){
$name= $name??"Guest";
$age=$age??0;
echo "Hello my name is $name my age is $age \n";
}
Test(age:44, name:"Ambiorix");
?>
Output:
9 ms | 18.4 MBHello my name is Ambiorix my age is 44
<?php
class Human{
// Class variables
public static int $globalID = 1000;
//Instance variables
private string $name;
private int $instanceNumId;
//Constructor initializer
public function __construct(string $name){
$this->intanceNumId=self::$globalID+=1;
$this->name=$name;
}
//Getter methods
function getId(){
return $this->intanceNumId;
}
function getName(){
return $this->name;
}
}
//Class instances
$Test0 = new Human("Class 0");
$Test1 = new Human("Class 1");
echo "--- Instance ID {$Test0->getId()}\n";
echo "--- Instance ID {$Test1->getId()}\n";
//Accessing class static fields
echo " Global class ID ".Human::$globalID." , instance name {$Test0->getName()} \n";
?>