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);
?> |
<?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();
?> |
<?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();
?>