search
Homephp教程php手册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();
以上是学习的时候参考的例子,分下下.....如果有疑问,我们可以讨论

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.