Fix #72462: documentation about static calls from secondary object is outdated

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@339436 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christoph Michael Becker 2016-06-21 14:38:50 +00:00
parent 707cc32e4b
commit 4392990fb6
2 changed files with 22 additions and 5 deletions

View file

@ -151,7 +151,7 @@ class B {
?>
]]>
</programlisting>
&example.outputs.5;
&example.outputs.56;
<screen>
<![CDATA[
Deprecated: Non-static method A::test() should not be called statically, assuming $this from incompatible context in /tmp/test.php on line 8

View file

@ -52,10 +52,21 @@ class SimpleClass
possibly another object, if the method is called
<link linkend="language.oop5.static">statically</link> from the context
of a secondary object).
As of PHP 7.0.0 calling a non-static method statically from an incompatible
context results in $this being undefined inside the method. Calling a
non-static method statically from an incompatible context has been
deprecated as of PHP 5.6.0. As of PHP 7.0.0 calling a non-static method
statically has been generally deprecated (even if called from a compatible
context). Before PHP 5.6.0 such calls already triggered a strict notice.
</para>
<para>
<example xml:id="language.oop5.basic.class.this">
<title>Some examples of the <varname>$this</varname> pseudo-variable</title>
<simpara>
We're assuming that error_reporting is disabled for this example;
otherwise the following code would trigger deprecated and strict notices,
respectively, depending on the PHP version.
</simpara>
<programlisting role="php">
<![CDATA[
<?php
@ -77,7 +88,6 @@ class B
{
function bar()
{
// Note: the next line will issue a warning if E_STRICT is enabled.
A::foo();
}
}
@ -85,23 +95,30 @@ class B
$a = new A();
$a->foo();
// Note: the next line will issue a warning if E_STRICT is enabled.
A::foo();
$b = new B();
$b->bar();
// Note: the next line will issue a warning if E_STRICT is enabled.
B::bar();
?>
]]>
</programlisting>
&example.outputs;
&example.outputs.5;
<screen>
<![CDATA[
$this is defined (A)
$this is not defined.
$this is defined (B)
$this is not defined.
]]>
</screen>
&example.outputs.7;
<screen>
<![CDATA[
$this is defined (A)
$this is not defined.
$this is not defined.
$this is not defined.
]]>
</screen>
</example>