摘要:
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 阅读全文
摘要:
1. namespace: 和C++中的名字空间很像,作用也一样,都是为了避免在引用较多第三方库时而带来的名字冲突问题。通过名字空间,即便两个class的名称相同,但是因为位于不同的名字空间内,他们仍然可以被精确定位和区分。第一次看到PHP的名字空间语法时,感觉和C++相比在语法上是非常非常相似的,然而在写点儿小例子做做实验的时候才发现,他们的差别还是很大的,为了避免以后忘记,所以这里特别将其记录了下来。见如下代码:getName(); if ($c->isUserDefined()) { $details .= "$name is user defined.\n"; 阅读全文
摘要:
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 阅读全文