OOP public

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: OOP public

OOP public

โดย offing » 30/01/2015 9:43 am

public คือ สามารถเรียกใช้งานได้เลยจากภายนอกโดยไม่ได้ป้องกันอะไร

โค้ด: เลือกทั้งหมด

<?php
class square { //สร้างคลาส
    public $width; //ประกาศ property
    public $subject = 'ขนาดพื้นที่'; //^
    public $height; // ^
    public function calculate($width,$height) { //สร้าง method
        echo $width*$height; 
    }
}
$obj=new square; //เรียกใช้ class
echo $obj->subject; //แสดงผล property ที่ใช้ visibility public
echo "</br>";
$obj->calculate('4','8'); //เรียกใช้ method ในคลาส square

?>
OUTPUT
1.gif
1.gif (1.29 KiB) Viewed 488 times

ข้างบน