随笔分类 -  面向对象

摘要:1 name = 'James'; 7 echo $james->name.""; 8 9 $james2 = clone $james;10 echo "before set up James2's:".$james2->name."";11 12 $james2->name = 'James... 阅读全文
posted @ 2015-07-04 16:10 todaytoday 阅读(224) 评论(0) 推荐(0) 编辑
摘要:__get(),__set(),__isset(),__unset()在给不可访问属性赋值时,__set()会被调用读取不可访问属性的值时,__get()会被调用当对不可访问属性调用isset()或empty()时,__isset()会被调用当对不可访问属性调用unset()时,__unset()会... 阅读全文
posted @ 2015-07-04 15:55 todaytoday 阅读(232) 评论(0) 推荐(0) 编辑
摘要:__call() 当对象访问不存在的方法时,__call()方法会被自动调用__callStatic() 当对象访问不存在的静态方法时,__callStatic()方法会被自动调用这两个方法在PHP里面也叫方法的重载(overloading) 注意区分重写(overwrite) 通过... 阅读全文
posted @ 2015-07-04 15:24 todaytoday 阅读(4219) 评论(0) 推荐(0) 编辑
摘要:首先放上代码: 1 ";10 }11 }12 13 $obj = new MagicTest();14 echo $obj."";15 $obj(5);输出为:This is the class MagicTest__invoke called with parameter5可以看到调用$o... 阅读全文
posted @ 2015-07-04 14:37 todaytoday 阅读(214) 评论(0) 推荐(0) 编辑
摘要:1 ";12 }13 }14 class animal implements ICanEat{15 //实现了某个接口之后,必须提供接口中定义的方法的具体实现16 public function eat($food) {17 echo "Animal eat... 阅读全文
posted @ 2015-07-04 13:29 todaytoday 阅读(707) 评论(0) 推荐(0) 编辑
摘要:1 "; 6 } 7 } 8 9 class ChildClass extends BaseClass{10 const CONST_VALUE = "A constant value";11 private static $sValue = "static Value"... 阅读全文
posted @ 2015-07-04 12:52 todaytoday 阅读(217) 评论(0) 推荐(0) 编辑
摘要:1 "; 6 } 7 public function test1() { 8 echo "BaseClass::test1 called".""; 9 }10 }11 12 class ChildClass extends BaseClass{13 ... 阅读全文
posted @ 2015-07-04 12:38 todaytoday 阅读(565) 评论(0) 推荐(0) 编辑
摘要:通过函数改变内部属性的值: 1 president = $newPrsdt;21 } 22 }23 24 $jordan = new NbaPlayer("Jordan","198cm","98kg","Bull","23");25 $james = new NbaPlayer("Jam... 阅读全文
posted @ 2015-07-04 11:30 todaytoday 阅读(224) 评论(0) 推荐(0) 编辑
摘要:探究public , private , protected三种类型的数据的访问控制其中public能被自身 , 子类 ,外部 访问;protected 能被自身和子类访问,不能被外部直接访问;private 只能被自身访问,不能被子类和外部访问。 1 name." is eating ".$foo... 阅读全文
posted @ 2015-07-04 10:52 todaytoday 阅读(246) 评论(0) 推荐(0) 编辑
摘要:1 name." is eating ".$food."";10 }11 }12 13 //php中可以使用extends关键字表示类的继承,后面跟父类的类名14 //php中extends后面只能跟一个类的类名,这就是php的单继承原则15 class NbaPlayer extends... 阅读全文
posted @ 2015-07-04 10:26 todaytoday 阅读(169) 评论(0) 推荐(0) 编辑
摘要:首先创建一个类,然后加入方法,并使用构造函数和析构函数 1 ";13 $this->name = $name; //$this 是php里面的伪变量,表示对象自身,可以通过$this->的方式访问对象的属性和方法14 $this->height = $height;... 阅读全文
posted @ 2015-07-04 10:03 todaytoday 阅读(245) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示