PHP Class Example

Here is a simple example of Class in PHP.

<?php
class EmpDetails {
var $property1;
var $property2; 
function display($name, $age) {
	print "Employee name is : $name<br>";
	print "Employee age is: $age<br>";
}
}
 
$obj = &new EmpDetails ;
$obj->name = 'Designer';
$obj->age = '26';
$obj->display($obj->name, $obj->age);
 
?>

Another Example of Classes In PHP

<?php 
ini_set('display_errors', 1); 
error_reporting(E_ALL); 
require_once 'Mysql.class.php'; 
 
class Test 
{ 
   private $db; 
 
   public function __construct() 
   { 
      $this->db = Mysql::singleton(); 
   } 
 
   public function listCustomers() 
   { 
      $result = $this->db->select('SELECT * FROM customers'); 
      return $result->getTable(true); 
   } 
} 
 
$test = new Test(); 
echo $test->listCustomers();
?>
Tags:

Related posts:

HTML5 page structure

HTML5 offers more powerful structure comparing to older versions of Html. There are many new …


Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us