language/references.xml
6d29533483657c036e49edb5ea88c7103d126681
...
...
@@ -74,7 +74,7 @@ $b = array();
74
74
foo($b['b']);
75
75
var_dump(array_key_exists('b', $b)); // bool(true)
76
76

77
-
$c = new StdClass;
77
+
$c = new stdClass;
78
78
foo($c->d);
79
79
var_dump(property_exists($c, 'd')); // bool(true)
80
80
?>
...
...
@@ -95,17 +95,13 @@ $foo =& find_var($bar);
95
95
]]>
96
96
</programlisting>
97
97
</informalexample>
98
-
Since PHP 5, <link linkend="language.oop5.basic.new">new</link>
99
-
returns a reference automatically, so
100
-
using <literal>=&amp;</literal> in this context is deprecated and
101
-
produces an <constant>E_DEPRECATED</constant> message in PHP 5.3 and
102
-
later, and an <constant>E_STRICT</constant> message in earlier versions.
103
-
As of PHP 7.0 it is syntactically invalid.
104
-
(Technically, the difference is that, in PHP 5, object variables, much like
105
-
resources, are a mere pointer to the actual object data, so these object
106
-
references are not "references" in the same sense used before (aliases).
107
-
For more information, see <link linkend="language.oop5.references">Objects
108
-
and references</link>.)
98
+
</para>
99
+
<para>
100
+
Using the same syntax with a function that does <emphasis>not</emphasis>
101
+
return by reference will give an error, as will using it with the result
102
+
of the <link linkend="language.oop5.basic.new">new</link> operator.
103
+
Although objects are passed around as pointers, these are not the same as references,
104
+
as explained under <link linkend="language.oop5.references">Objects and references</link>.
109
105
</para>
110
106
<warning>
111
107
<para>
...
...
@@ -315,11 +311,7 @@ foo($a);
315
311
<simpara>
316
312
There is no reference sign on a function call - only on
317
313
function definitions. Function definitions alone are enough to
318
-
correctly pass the argument by reference. As of PHP 5.3.0,
319
-
you will get a warning saying that "call-time pass-by-reference" is
320
-
deprecated when you use &amp; in <literal>foo(&amp;$a);</literal>.
321
-
And as of PHP 5.4.0, call-time pass-by-reference was removed, so
322
-
using it will raise a fatal error.
314
+
correctly pass the argument by reference.
323
315
</simpara>
324
316
</note>
325
317
</para>
...
...
@@ -375,8 +367,7 @@ function bar() // Note the missing &
375
367
$a = 5;
376
368
return $a;
377
369
}
378
-
foo(bar()); // Produces fatal error as of PHP 5.0.5, strict standards notice
379
-
// as of PHP 5.1.1, and notice as of PHP 7.0.0
370
+
foo(bar()); // Produces a notice
380
371

381
372
foo($a = 5); // Expression, not variable
382
373
foo(5); // Produces fatal error
...
...
@@ -443,9 +434,6 @@ echo $myValue; // prints the new value of $obj->value, i.e. 2.
443
434
work as you are attempting to return the result of an
444
435
<emphasis>expression</emphasis>, and not a variable, by reference. You can
445
436
only return variables by reference from a function - nothing else.
446
-
Since PHP 5.1.0, an
447
-
<constant>E_NOTICE</constant> error is issued if the code tries to return
448
-
a dynamic expression or a result of the <literal>new</literal> operator.
449
437
</simpara>
450
438
</note>
451
439
<para>
...
...
@@ -544,14 +532,6 @@ $var =& $GLOBALS["var"];
544
532
won't unset the global variable.
545
533
</simpara>
546
534
</sect2>
547
-

548
-
<sect2 xml:id="references.this">
549
-
<title><literal>$this</literal></title>
550
-
<simpara>
551
-
In an object method, <varname>$this</varname> is always a reference
552
-
to the called object.
553
-
</simpara>
554
-
</sect2>
555
535
</sect1>
556
536

557
537
</chapter>
558
538