martes, 17 de febrero de 2026

Oop Guide practice

 <?php




/* 1 Creawte the class  */



class Human{

  

  /* Create  a public static prop and initialize it before accesing */

  


   public static int $globaID=1000;  // enforce type to be int and static

  

   private static int $baseId =1000;

   

   private  int $intanceNumId;

   

   public string $name;

  

  

  

  /* Create a constructor */

  public function __construct(string $name){

   // $Human::$base+=1;

    

$this->intanceNumId=self::$baseId+=1;

$this->name=$name;

    

  }

  

  function getId(){

    

    return $this->intanceNumId;

  }

}


$Test0 =  new Human("Class 0");


$Test1 =  new Human("Class 1");


echo  " Global  class ID ".Human::$globaID." , instance name {$Test0->name}  \n";


echo  "--- Instance ID  {$Test0->getId()}\n";


echo  "--- Instance ID  {$Test1->getId()}\n";


?>