You can get an object using new keyword followed by class name.
Syntax
$obj1 = new ClassName;
$obj2 = new ClassName(arguments);
Let’s try 1st syntax, I will explain second syntax in upcoming posts.
new_instance_demo.php
#!/usr/bin/php
<?php
class Employee{
}
$emp1 = new Employee;
echo '$emp1 is an instance of ' . get_class($emp1);
?>
Output
$./new_instance_demo.php
$emp1 is an instance of Employee
No comments:
Post a Comment