mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Don't use <function> for magic methods
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@322134 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
bc09a56fb5
commit
28d123ef98
15 changed files with 38 additions and 41 deletions
|
@ -107,11 +107,11 @@ print 10 % 0;
|
|||
</listitem>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Changed <function>__toString</function> to be called wherever
|
||||
Changed <link linkend="object.tostring">__toString()</link> to be called wherever
|
||||
applicable.
|
||||
</simpara>
|
||||
<simpara>
|
||||
The magic method <function>__toString</function> will now be called
|
||||
The magic method <link linkend="object.tostring">__toString()</link> will now be called
|
||||
in a string context, that is, anywhere an object is used as a
|
||||
string.
|
||||
</simpara>
|
||||
|
@ -138,7 +138,7 @@ print $foo;
|
|||
</programlisting>
|
||||
</informalexample>
|
||||
<simpara>
|
||||
Even with <function>__toString</function>, objects cannot be used as
|
||||
Even with <link linkend="object.tostring">__toString()</link>, objects cannot be used as
|
||||
array indices or keys. We may add built-in hash support for this at
|
||||
a later date, but as of PHP 5.2.x you will need to either provide your
|
||||
own hashing or use the new SPL function
|
||||
|
@ -146,7 +146,7 @@ print $foo;
|
|||
</simpara>
|
||||
<simpara>
|
||||
Exceptions can not be thrown from
|
||||
<function>__toString</function> methods.
|
||||
<link linkend="object.tostring">__toString()</link> methods.
|
||||
</simpara>
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
you want to use documented magical functionality. Examples:
|
||||
</para>
|
||||
<itemizedlist>
|
||||
<listitem><para><function>__get</function></para></listitem>
|
||||
<listitem><para><link linkend="object.get">__get()</link></para></listitem>
|
||||
<listitem><para><function>__autoload</function></para></listitem>
|
||||
</itemizedlist>
|
||||
</listitem>
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<entry>5.3.0</entry>
|
||||
<entry>
|
||||
Changed: Prior to 5.3.0, exceptions thrown in the
|
||||
<link linkend="language.oop5.autoload">__autoload</link> function could not be
|
||||
<function>__autoload</function> function could not be
|
||||
caught in the <link linkend="language.exceptions">catch</link> block, and
|
||||
would result in a fatal error. Exceptions now thrown in the __autoload function
|
||||
can be caught in the <link linkend="language.exceptions">catch</link> block, with
|
||||
|
|
|
@ -50,17 +50,17 @@ $obj = new SubClass();
|
|||
</example>
|
||||
<para>
|
||||
For backwards compatibility, if PHP 5 cannot find a
|
||||
<function>__construct</function> function for a given class, it will
|
||||
<link linkend="object.construct">__construct()</link> function for a given class, it will
|
||||
search for the old-style constructor function, by the name of the class.
|
||||
Effectively, it means that the only case that would have compatibility
|
||||
issues is if the class had a method named
|
||||
<function>__construct</function> which was used for different semantics.
|
||||
<link linkend="object.construct">__construct()</link> which was used for different semantics.
|
||||
</para>
|
||||
<para>
|
||||
Unlike with other methods, PHP will not generate an
|
||||
<constant>E_STRICT</constant> level error message when
|
||||
<function>__construct</function> is overridden with different parameters
|
||||
than the parent <function>__construct</function> method has.
|
||||
<link linkend="object.construct">__construct()</link> is overridden with different parameters
|
||||
than the parent <link linkend="object.construct">__construct()</link> method has.
|
||||
</para>
|
||||
<para>
|
||||
As of PHP 5.3.3, methods with the same name as the last element of a
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<title>Magic Methods</title>
|
||||
<para>
|
||||
The function names
|
||||
<link linkend="language.oop5.decon.constructor">__construct()</link>,
|
||||
<link linkend="language.oop5.decon.destructor">__destruct()</link>,
|
||||
<link linkend="object.construct">__construct()</link>,
|
||||
<link linkend="object.destruct">__destruct()</link>,
|
||||
<link linkend="language.oop5.overloading.methods">__call()</link>,
|
||||
<link linkend="language.oop5.overloading.methods">__callStatic()</link>,
|
||||
<link linkend="language.oop5.overloading.members">__get()</link>,
|
||||
|
|
|
@ -58,14 +58,14 @@
|
|||
<row>
|
||||
<entry>5.3.0</entry>
|
||||
<entry>
|
||||
Added <function>__callStatic</function>.
|
||||
Added <link linkend="object.callstatic">__callStatic()</link>.
|
||||
Added warning to enforce public visibility and non-static declaration.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>5.1.0</entry>
|
||||
<entry>
|
||||
Added <function>__isset</function> and <function>__unset</function>.
|
||||
Added <link linkend="object.isset">__isset()</link> and <link linkend="object.unset">__unset()</link>.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
|
@ -97,29 +97,29 @@
|
|||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
<function>__set</function> is run when writing data to
|
||||
<link linkend="object.set">__set()</link> is run when writing data to
|
||||
inaccessible properties.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<function>__get</function> is utilized for reading data from
|
||||
<link linkend="object.get">__get()</link> is utilized for reading data from
|
||||
inaccessible properties.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<function>__isset</function> is triggered by calling
|
||||
<link linkend="object.isset">__isset()</link> is triggered by calling
|
||||
<function>isset</function> or <function>empty</function>
|
||||
on inaccessible properties.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<function>__unset</function> is invoked when
|
||||
<link linkend="object.unset">__unset()</link> is invoked when
|
||||
<function>unset</function> is used on inaccessible properties.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The <varname>$name</varname> argument is the name of the
|
||||
property being interacted with. The <function>__set</function>
|
||||
property being interacted with. The <link linkend="object.set">__set()</link>
|
||||
method's <varname>$value</varname> argument specifies the
|
||||
value the <varname>$name</varname>'ed property should be set
|
||||
to.
|
||||
|
@ -136,9 +136,9 @@
|
|||
|
||||
<note>
|
||||
<para>
|
||||
The return value of <function>__set</function> is ignored
|
||||
The return value of <link linkend="object.set">__set()</link> is ignored
|
||||
because of the way PHP processes the assignment operator.
|
||||
Similarly, <function>__get</function> is never called when
|
||||
Similarly, <link linkend="object.get">__get()</link> is never called when
|
||||
chaining assignments together like this:
|
||||
<literal><![CDATA[ $a = $obj->b = 8; ]]></literal>
|
||||
</para>
|
||||
|
@ -160,9 +160,9 @@
|
|||
|
||||
<example>
|
||||
<title>
|
||||
Overloading properties via the <function>__get</function>,
|
||||
<function>__set</function>, <function>__isset</function>
|
||||
and <function>__unset</function> methods
|
||||
Overloading properties via the <link linkend="object.get">__get()</link>,
|
||||
<link linkend="object.set">__set()</link>, <link linkend="object.isset">__isset()</link>
|
||||
and <link linkend="object.unset">__unset()</link> methods
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
@ -288,12 +288,12 @@ Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> o
|
|||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
<function>__call</function> is triggered when invoking
|
||||
<link linkend="object.call">__call()</link> is triggered when invoking
|
||||
inaccessible methods in an object context.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<function>__callStatic</function> is triggered when invoking
|
||||
<link linkend="object.callstatic">__callStatic()</link> is triggered when invoking
|
||||
inaccessible methods in a static context.
|
||||
</para>
|
||||
|
||||
|
@ -306,8 +306,8 @@ Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> o
|
|||
|
||||
<example>
|
||||
<title>
|
||||
Overloading methods via the <function>__call</function>
|
||||
and <function>__callStatic</function> methods
|
||||
Overloading methods via the <link linkend="object.call">__call()</link>
|
||||
and <link linkend="object.callstatic">__callStatic()</link> methods
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
|
|
@ -2053,7 +2053,7 @@ bool(false)
|
|||
</para>
|
||||
<para>
|
||||
There are a few pitfalls to be aware of. Before PHP version 5.1.0,
|
||||
<literal>instanceof</literal> would call <link linkend="language.oop5.autoload">__autoload()</link>
|
||||
<literal>instanceof</literal> would call <function>__autoload</function>
|
||||
if the class name did not exist. In addition, if the class was not loaded,
|
||||
a fatal error would occur. This can be worked around by using a dynamic
|
||||
class reference, or a string variable containing the class name:
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<para>
|
||||
This method acts as the
|
||||
<link linkend="language.oop5.decon.destructor">destructor</link> of the object. The
|
||||
<function>__destruct</function> method will <emphasis>not</emphasis> be called after this
|
||||
<link linkend="object.destruct">__destruct()</link> method will <emphasis>not</emphasis> be called after this
|
||||
method.
|
||||
</para>
|
||||
</note>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<para>
|
||||
This method acts as the
|
||||
<link linkend="language.oop5.decon.constructor">constructor</link> of the object. The
|
||||
<function>__construct</function> method will <emphasis>not</emphasis> be called after this
|
||||
<link linkend="object.construct">__construct()</link> method will <emphasis>not</emphasis> be called after this
|
||||
method.
|
||||
</para>
|
||||
</note>
|
||||
|
|
|
@ -102,7 +102,7 @@ string(5) "1-2-3"
|
|||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<simplelist>
|
||||
<member><link linkend="language.oop5.overloading.methods"><function>__call</function></link></member>
|
||||
<member><link linkend="object.call">__call()</link></member>
|
||||
</simplelist>
|
||||
</refsect1>
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
&reftitle.errors;
|
||||
<para>
|
||||
Throws <classname>BadMethodCallException</classname> if
|
||||
<function>__construct</function> is called twice.
|
||||
<link linkend="object.construct">__construct()</link> is called twice.
|
||||
Throws <classname>UnexpectedValueException</classname> if
|
||||
the phar URL requested is malformed, the requested
|
||||
phar cannot be opened, or the file can't be found within the phar.
|
||||
|
|
|
@ -69,8 +69,8 @@
|
|||
<para>
|
||||
The main interface through which data objects are manipulated. In
|
||||
addition to the methods below, SDO_DataObject extends the
|
||||
ArrayAccess, SDO_PropertyAccess (defines <function>__get</function> /
|
||||
<function>__set</function> methods for property access overloading),
|
||||
ArrayAccess, SDO_PropertyAccess (defines <link linkend="object.get">__get()</link> /
|
||||
<link linkend="object.set">__set()</link> methods for property access overloading),
|
||||
Iterator, and Countable interfaces.
|
||||
</para>
|
||||
<section> &reftitle.methods;
|
||||
|
|
|
@ -37,8 +37,7 @@
|
|||
<listitem>
|
||||
<para>
|
||||
Whether to allow this function to load the class automatically through
|
||||
the <link linkend="language.oop5.autoload">__autoload</link> magic
|
||||
method.
|
||||
the <function>__autoload</function> magic method.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
|
|
@ -37,8 +37,7 @@
|
|||
<listitem>
|
||||
<para>
|
||||
Whether to allow this function to load the class automatically through
|
||||
the <link linkend="language.oop5.autoload">__autoload</link> magic
|
||||
method.
|
||||
the <function>__autoload</function> magic method.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
|
|
@ -38,8 +38,7 @@
|
|||
<listitem>
|
||||
<para>
|
||||
Whether to allow this function to load the class automatically through
|
||||
the <link linkend="language.oop5.autoload">__autoload</link> magic
|
||||
method.
|
||||
the <function>__autoload</function> magic method.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
|
Loading…
Reference in a new issue