Home / PHP/MySQL Tutorials / Object Oriented PHP / Archive by category 'Classes/Objects'

Classes/Objects

Example process of creating classes and objects in PHP

<?php
class emp
{
   var $name;
   var $address;
   var $dept;
   function assign_info($n,$a,$d)
   {
      $this->name=$n;
      $this->state=$a;
      $this->dept=$d;
   }
   function display_info()
   {
      echo("<p>Employee Name : $this->name");
      echo("<p>State : $this->state");
      echo("<p>Department : $this->dept");
   }
}
$empobj = new emp;
$empobj->assign_info("kaka lname","California","Accounts");
echo("<center><h2>Displaying Employee Information</h2></center>");
echo("<font size=4>");
$empobj->display_info();
echo("</font>");
?>