随笔分类 -  PHP编程

摘要:1. call_user_func和call_user_func_array: 以上两个函数以不同的参数形式调用回调函数。见如下示例: $arg) { print "$arg\n"; }}myTest('hello','world','123456'); 运行结果如下:Stephens-Air:TestPhp$ php class_exist_test.php The number of args in myTest is 3The 0th arg is helloThe 1th arg is worldThe 2th arg 阅读全文
posted @ 2014-01-08 09:22 OrangeAdmin 阅读(2857) 评论(5) 推荐(0) 编辑
摘要:1. interface_exists、class_exists、method_exists和property_exists: 顾名思义,从以上几个函数的命名便可以猜出几分他们的功能。我想这也是我随着对PHP的深入学习而越来越喜欢这门编程语言的原因了吧。下面先给出他们的原型声明和简短说明,更多的还是直接看例子代码吧。bool interface_exists (string $interface_name [, bool $autoload = true ]) 判断接口是否存在,第二个参数表示在查找时是否执行__autoload。bool class_exists (string $cla.. 阅读全文
posted @ 2014-01-06 09:23 OrangeAdmin 阅读(11414) 评论(1) 推荐(3) 编辑
摘要:1. namespace: 和C++中的名字空间很像,作用也一样,都是为了避免在引用较多第三方库时而带来的名字冲突问题。通过名字空间,即便两个class的名称相同,但是因为位于不同的名字空间内,他们仍然可以被精确定位和区分。第一次看到PHP的名字空间语法时,感觉和C++相比在语法上是非常非常相似的,然而在写点儿小例子做做实验的时候才发现,他们的差别还是很大的,为了避免以后忘记,所以这里特别将其记录了下来。见如下代码:getName(); if ($c->isUserDefined()) { $details .= "$name is user defined.\n"; 阅读全文
posted @ 2014-01-04 09:07 OrangeAdmin 阅读(5942) 评论(0) 推荐(4) 编辑
摘要:1. __toString: 当对象被打印时,如果该类定义了该方法,则打印该方法的返回值,否则将按照PHP的缺省行为输出打印结果。该方法类似于Java中的toString()。privateField = "This is a private Field.\n"; $this->publicField = "This is a public Field.\n"; } public function __get($property) { print "__get() is called.\n"; $method = "g 阅读全文
posted @ 2014-01-02 08:53 OrangeAdmin 阅读(3007) 评论(1) 推荐(4) 编辑
摘要:1. __construct: 内置构造函数,在对象被创建时自动调用。见如下代码:arg1 = $arg1; $this->arg2 = $arg2; print "__construct is called...\n"; } public function printAttributes() { print '$arg1 = '.$this->arg1.' $arg2 = '.$this->arg2."\n"; }}$testObject = new ConstructTest("arg1&q 阅读全文
posted @ 2013-12-31 08:56 OrangeAdmin 阅读(11568) 评论(2) 推荐(8) 编辑

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