Home Backend Development PHP Tutorial php _call and _callStatic

php _call and _callStatic

Jun 13, 2016 am 10:49 AM
context name static

php __call and __callStatic

PHP5?的对象新增了一个专用方法?__call(),这个方法用来监视一个对象中的其它方法。如果你试着调用一个对象中不存在的方法,__call?方法将会被自动调用。

?

__call()?is triggered when invoking inaccessible methods in an object context.

__callStatic()?is triggered when invoking inaccessible methods in a static context.

?

class?MethodTest?{
????public?function?
__call($name,?$arguments)?{
????????
//?Note:?value?of?$name?is?case?sensitive.
????????
echo?"Calling?object?method?'$name'?"
?????????????
.?implode(',?',?$arguments).?"\n";
????}

????
/**??As?of?PHP?5.3.0??*/
????
public?static?function?__callStatic($name,?$arguments)?{
????????
//?Note:?value?of?$name?is?case?sensitive.
????????
echo?"Calling?static?method?'$name'?"
?????????????
.?implode(',?',?$arguments).?"\n";
????}
}

$obj?=?new?MethodTest;
$obj->runTest('in?object?context');

MethodTest::runTest('in?static?context');??//?As?of?PHP?5.3.0
?>

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does context mean? What does context mean? Aug 04, 2023 pm 05:27 PM

Context is the environment and status information when the program is executed. It can include a variety of information, such as the value of variables, the call stack of functions, the execution location of the program, etc., allowing the program to make corresponding decisions based on different contexts. and perform corresponding operations.

How to use context to implement request caching in Go How to use context to implement request caching in Go Jul 22, 2023 pm 10:51 PM

How to use context to implement request caching in Go Introduction: When building web applications, we often need to cache requests to improve performance. In the Go language, we can use the context package to implement the request caching function. This article will introduce how to use the context package to implement request caching, and provide code examples to help readers better understand. What is context? : In the Go language, the context package provides a way to pass between multiple goroutines

How to use context to implement request link tracking in Go How to use context to implement request link tracking in Go Jul 21, 2023 pm 05:57 PM

How to use context to implement request link tracking in Go. In the microservice architecture, request link tracking is a very important technology that is used to track the delivery and processing of a request between multiple microservices. In the Go language, we can use the context package to implement request link tracking. This article will introduce how to use context for request link tracking and give code examples. First, we need to understand the basic concepts and usage of the context package. The context package provides a mechanism

How to use context to pass request parameters in Go How to use context to pass request parameters in Go Jul 22, 2023 pm 04:43 PM

The context package in the Go language is used to pass request context information in the program. It can pass parameters, intercept requests and cancel operations between functions across multiple Goroutines. To use the context package in Go, we first need to import the "context" package. Below is an example that demonstrates how to use the context package to implement request parameter passing. packagemainimport("context&quot

How to use context to implement request timeout control in Go How to use context to implement request timeout control in Go Jul 21, 2023 pm 12:18 PM

How to use context to implement request timeout control in Go Introduction: When we make network requests, we often encounter request timeout problems. A network request that does not respond for a long time will not only waste server resources, but also affect overall performance. In order to solve this problem, the Go language introduced the context package, which can be used to implement request timeout control. This article will introduce how to use the context package to implement request timeout control in Go, and attach corresponding code examples. 1. Understand the context package co

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to elegantly use Go and context for error handling How to elegantly use Go and context for error handling Jul 21, 2023 pm 11:37 PM

How to use Go and context elegantly for error handling In Go programming, error handling is a very important task. Handling errors gracefully improves code readability, maintainability, and stability. The context package of Go language provides us with a very convenient way to handle error-related operations. This article will introduce how to use Go and context elegantly for error handling, and provide relevant code examples. Introduction The error handling mechanism of Go language is implemented by returning an error value.

How to use context to implement request retry strategy in Go How to use context to implement request retry strategy in Go Jul 21, 2023 pm 04:39 PM

How to use context to implement request retry strategy in Go Introduction: When building a distributed system, network requests will inevitably encounter some failures. In order to ensure the reliability and stability of the system, we usually use a retry strategy to handle these failed requests to increase the success rate of the request. In the Go language, we can use the context package to implement the request retry strategy. This article will introduce how to use the context package in Go to implement a request retry strategy, with code examples. 1. What is

See all articles