php中 重载(二)
php中 重载(二)
接着上一次说的重载,我们了解下php中的重载,方法的重载,如果有管重载定义,参考:php中 重载(一)这个文章,谢谢.作为初学者,大牛勿喷:
基本是两个方法
__call,当调用对一个不可访问的对象方法时,会自动执行该魔术方法!(对象调用)
典型的两种处理方式:
1,给出友好的提示!
2,执行默认操作!
__callstatic,当调用一个不可访问的静态方法时,会自动执行该魔术方法!
详细代码:
class Student {
public $name = 'php';
public $age = 10;
public function sayName() {
return $this->name;
}
/**
* @param $method_name string 方法名
* @param $method_arguments array 调用时携带的参数
*/
public function __call($method_name, $method_arguments) {
echo '
抱歉, 你调用的方法不存在!,你应该调用(***)方法!';
$this->defaultAction();//执行默认的方法,可以做跳转用,实现redirect
}
public function defaultAction() {
echo '
这里是默认动作!';
}
public static function __callStatic($m_name, $m_args) {
echo '这里是静态的方法重载!';
}
}
Student::sayCounter();
以上是学习的时候参考的例子,分下下.....如果有疑问,我们可以讨论

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
