PHP programs to pass an object of class as an argument

bookmark

<?php
//PHP programs to pass an object of class as an argument.
class Student
{
    public $Id;
    public $Name;
}

function Set(Student $S, $id, $name)
{
    $S->Id = $id;
    $S->Name = $name;
}
function Display(Student $S)
{
    printf("Id  : " . $S->Id . "<br>");
    printf("Name: " . $S->Name . "<br>");
}

$S = new Student();

Set($S, 101, "Rahul");
Display($S);

?>


Output
Id : 101
Name: Rahul