Home > Backend Development > PHP Tutorial > Overloading in php (2)_PHP tutorial

Overloading in php (2)_PHP tutorial

WBOY
Release: 2016-07-13 10:17:16
Original
904 people have browsed it

PHP reload (2)

Continuing with the overloading mentioned last time, let’s learn about overloading in PHP and method overloading. If there is a definition of overloading, please refer to: Overloading in PHP (1). Thank you. As a beginner, Big cows, please don’t spray:

Basically there are two methods

__call, when calling a method on an inaccessible object, this magic method will be automatically executed! (Object call)

Two typical processing methods:

1. Give friendly tips!

2, perform the default operation!

__callstatic, when an inaccessible static method is called, this magic method will be automatically executed!

Detailed code:

class Student {
public $name = 'php';
public $age = 10;

public function sayName() {
return $this->name;
}

/**
* @param $method_name string method name
* @param $method_arguments array Parameters carried when calling
*/
public function __call($method_name, $method_arguments) {
echo '
Sorry, the method you called does not exist!, you should call the (***) method! ';

$this->defaultAction();//Execute the default method, which can be used for jumps and redirect


}

public function defaultAction() {
echo '
This is the default action! ';
}

public static function __callStatic($m_name, $m_args) {
echo 'This is static method overloading! ';
}
}
Student::sayCounter();
The above are examples for reference when studying. They are divided below... If you have any questions, we can discuss

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/894187.htmlTechArticleOverloading in php (2) Following the overloading mentioned last time, let’s learn about overloading in php. Method overloading, if there is an overloading definition, please refer to: Overloading in PHP (1) This article, thank you...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template