扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
class Something { // In OOP classes are usually named starting with a cap letter. var $x; function setX($v) { // Methods start in lowercase then use lowercase to seprate // words in the method name example getValueOfArea() $this->x=$v; } function getX() { return $this->x; } } ?> |
$obj = new Something; |
$obj->setX(5); $see = $obj->getX(); |
class Another extends Something { var $y; function setY($v) { // Methods start in lowercase then use lowercase to seperate // words in the method name example getValueOfArea() $this->y=$v; } function getY() { return $this->y; } } ?> |
$obj2=new Another; $obj2->setX(6); $obj2->setY(7); |
class Something { var $x; function Something($y) { $this->x=$y; } function setX($v) { $this->x=$v; } function getX() { return $this->x; } } ?> |
$obj=new Something(6); |
function Something($x="3",$y="5") |
$obj=new Something(); // x=3 and y=5 $obj=new Something(8); // x=8 and y=5 $obj=new Something(8,9); // x=8 and y=9 |
function Another() { $this->y=5; $this->Something(); //explicit call to base class constructor. } ?> |
class Myclass { function Myclass() { $name="Myclass".func_num_args(); $this->$name(); //Note that $this->$name() is usually wrong but here //$name is a string with the name of the method to call. } function Myclass1($x) { code; } function Myclass2($x,$y) { code; } } ?> |
$obj1=new Myclass(1); //Will call Myclass1 $obj2=new Myclass(1,2); //Will call Myclass2 |
濠碘€冲€归悘澶愬箖閵娾晜濮滈悽顖涚摃閹烩晠宕氶崶鈺傜暠闁诡垰鍘栫花锛勬喆椤ゅ弧濡澘妫楅悡娆撳嫉閳ь剟寮0渚€鐛撻柛婵呮缁楀矂骞庨埀顒勫嫉椤栨瑤绻嗛柟顓у灲缁辨繈鏌囬敐鍕杽閻犱降鍨藉Σ鍕嚊閹跺鈧﹦绱旈幋鐐参楅柡鍫灦閸嬫牗绂掔捄铏规闁哄嫷鍨遍崑宥夋儍閸曨剚浠樺ù锝嗗▕閳ь剚鏌ㄧ欢鐐寸▕鐎b晝顏遍柕鍡嫹