Ex.
php.class.php
<?php
class phpClass
{
var $width;
function example1(){
$this->width="100%";
echo "Example1: ".$this->width;
}// end function example1()
function example2(){
echo "Example2: ".$this->width;
}// end function example2()
}// end class
?>
การเรียกใช้
<?php
include_once("php.class.php");
$prg = new phpClass(); //กำหนดตัวแปรที่รับกับคลาสที่จะใช้
$prg->example1();
$prg->width = "50%";
$prg->example2();
?>
Output : Example1: 100%
Example2: 50%