หากท่านใดเคยเรียน ภาษาจาวาแล้ว หากจำได้ เรามักจะ ห่่อหุ้ม ตัวแปรของคลาสด้วย ด้วย method set() และ method get()
เช่นกันในภาษา php ก็สามารถทำได้ครับ
ดูโค๊ดล่างนี้
// File: Human.php
<?php
class Human
{
var $name ;
var $height;
var $weight;
function setName($name)
{
$this->name = $name;
}
function getName()
{
return $this->name;
}
}
?>
// File: TestClient.php
<?
require("Human.php");
$human = new Human();
$human->setName("Doing");
echo "My name is ".$human->getName();
?>
Result
-------------
My name is Doing