> For the complete documentation index, see [llms.txt](https://bing.gitbook.io/phper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bing.gitbook.io/phper/php/6.-chang-jian-wen-ti/mo-shu-fang-fa.md).

# 魔术方法

[\_\_construct()](https://www.php.net/manual/zh/language.oop5.decon.php#object.construct)

每次创建新对象时先调用此方法

[\_\_destruct()](https://www.php.net/manual/zh/language.oop5.decon.php#object.destruct)

某个对象的所有引用都被删除或者当对象被显式销毁时执行

[\_\_call()](https://www.php.net/manual/zh/language.oop5.overloading.php#object.call)

在对象中调用一个不可访问方法时，会被调用。

[\_\_callStatic()](https://www.php.net/manual/zh/language.oop5.overloading.php#object.callstatic)

在静态上下文中调用一个不可访问方法时，会被调用。

在给不可访问属性赋值时，[\_\_set()](https://www.php.net/manual/zh/language.oop5.overloading.php#object.set) 会被调用。

读取不可访问属性的值时，[\_\_get()](https://www.php.net/manual/zh/language.oop5.overloading.php#object.get) 会被调用。

当对不可访问属性调用 [isset()](https://www.php.net/manual/zh/function.isset.php) 或 [empty()](https://www.php.net/manual/zh/function.empty.php) 时，[\_\_isset()](https://www.php.net/manual/zh/language.oop5.overloading.php#object.isset) 会被调用。

当对不可访问属性调用 [unset()](https://www.php.net/manual/zh/function.unset.php) 时，[\_\_unset()](https://www.php.net/manual/zh/language.oop5.overloading.php#object.unset) 会被调用。

当尝试以调用函数的方式调用一个对象时，[\_\_invoke()](https://www.php.net/manual/zh/language.oop5.magic.php#object.invoke) 方法会被自动调用。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bing.gitbook.io/phper/php/6.-chang-jian-wen-ti/mo-shu-fang-fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
