PHP Class Structure

โพสเก็บไว้ เผื่อใช้อ้างอิงตอนหลัง PHP class structure ครับ
class Page {
var
$Title;
var
$Keywords;
var
$Content;

function
Display( ) {
echo
"\n\n";
$this->DisplayTitle( );
$this->DisplayKeywords( );
echo
"\n\n\n";
echo
$this->Content;
echo
"\n\n\n";
}

function
DisplayTitle( ) {
echo
"<title>" . $this->Title . "</title>\n";
}

function
DisplayKeywords( ) {
echo
'<meta name="keywords" content="">. $this->Keywords . '">';
}

function
SetContent( $Data ) {
$this->Content = $Data;
}
}

Now, at first glance this looks pretty simple. And you know what? It is. Its just basic PHP code wrapped into a class. Let me point a few things out before we go any farther though.

VAR -
All variables declared in the class must be placed at the top of the class structure, and preceeded with the VAR statement.

$THIS -
$this is a variable that incidates the current object. That way, the object knows how to find itself while running functions contained within it.
For instance, $this->Keywords gets the data from the $Keywords variable in the object. You'll also notice that when using variables contained
within a class, you can't use the $ to reference them - But you have to use it to reference the object itself.

1 comment:

  1. ดีไซน์ก็เก๋ พีเอชพีก็ได้ แถมภาษาอังกิดได้อีก !

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...