📄 language.oop5.overloading.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Overloading</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.oop5.interfaces.html">Object Interfaces</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.oop5.iterations.html">Object Iteration</a></div> <div class="up"><a href="language.oop5.html">Classes and Objects (PHP 5)</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="language.oop5.overloading" class="sect1"> <h2 class="title">Overloading</h2> <p class="para"> Overloading in PHP provides means to dynamically "<span class="quote">create</span>" members and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types. </p> <p class="para"> The overloading methods are invoked when interacting with members or methods that have not been declared or are not <a href="language.oop5.visibility.html" class="link">visible</a> in the current scope. The rest of this section will use the terms "<span class="quote">inaccessible members</span>" and "<span class="quote">inaccessible methods</span>" to refer to this combination of declaration and visibility. </p> <p class="para"> All overloading methods must be defined as <i>public</i>. </p> <blockquote><p><b class="note">Note</b>: None of the arguments of these magic methods can be <a href="functions.arguments.html#functions.arguments.by-reference" class="link">passed by reference</a>. <br /> </p></blockquote> <blockquote><p><b class="note">Note</b>: PHP's interpretation of "<span class="quote">overloading</span>" is different than most object oriented languages. Overloading traditionally provides the ability to have multiple methods with the same name but different quantities and types of arguments. <br /> </p></blockquote> <div id="language.oop5.overloading.changelog" class="sect2"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left"> Added <i>__isset()</i> and <i>__unset()</i>. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.3.0</td> <td colspan="1" rowspan="1" align="left"> Added <i>__callStatic()</i>. Added warning to enforce public visibility and non-static declaration. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div id="language.oop5.overloading.members" class="sect2"> <h3 class="title">Member overloading</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><b>__set</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$value</tt></span> )</div> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>__get</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span> )</div> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>__isset</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span> )</div> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><b>__unset</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span> )</div> <p class="para"> <i>__set()</i> is run when writing data to inaccessible members. </p> <p class="para"> <i>__get()</i> is utilized for reading data from inaccessible members. </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -