mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 17:08:54 +00:00
fix xml
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@43100 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
7c4ccc09bd
commit
0425348f09
1 changed files with 17 additions and 16 deletions
|
@ -209,7 +209,7 @@ class foo {
|
|||
function foo($name) {
|
||||
// create a reference inside the global array $globalref
|
||||
global $globalref;
|
||||
$globalref[] = &$this;
|
||||
$globalref[] = &$this;
|
||||
// set name to passed value
|
||||
$this->setName($name);
|
||||
// and put it out
|
||||
|
@ -217,7 +217,7 @@ class foo {
|
|||
}
|
||||
|
||||
function echoName() {
|
||||
echo "<br>",$this->Name;
|
||||
echo "<br>",$this->Name;
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
|
@ -226,11 +226,12 @@ class foo {
|
|||
}
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Let us check out if there is a difference between <varname>$bar1</varname> which has been created using the copy <literal>=</literal> operator
|
||||
and <varname>$bar2</varname> which has been created using the reference <literal>=&</literal> operator...
|
||||
</para>
|
||||
and <varname>$bar2</varname> which has been created using the reference <literal>=&</literal> operator...
|
||||
|
||||
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
|
@ -244,7 +245,7 @@ class foo {
|
|||
set in constructor
|
||||
set in constructor */
|
||||
|
||||
$bar2 =& new foo('set in constructor');
|
||||
$bar2 =& new foo('set in constructor');
|
||||
$bar2->echoName();
|
||||
$globalref[1]->echoName();
|
||||
|
||||
|
@ -255,7 +256,7 @@ class foo {
|
|||
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
||||
</para>
|
||||
<para>
|
||||
Apparently there is no difference, but in fact there is a very significant one:
|
||||
<varname>$bar1</varname> and <varname>$globalref[0]</varname> are _NOT_ referenced, they are NOT the same variable.
|
||||
|
@ -270,7 +271,7 @@ class foo {
|
|||
</simpara>
|
||||
</note>
|
||||
To prove what is written above let us watch the code below.
|
||||
</para>
|
||||
|
||||
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
|
@ -300,7 +301,7 @@ class foo {
|
|||
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
||||
</para>
|
||||
<para>
|
||||
Another final example, try to understand it.
|
||||
|
||||
|
@ -319,26 +320,26 @@ class a {
|
|||
}
|
||||
|
||||
function echoValue() {
|
||||
echo "<br>","class ",get_class($this),': ',$this->value;
|
||||
echo "<br>","class ",get_class($this),': ',$this->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class b {
|
||||
|
||||
function b(&$a) {
|
||||
$this->a = &$a;
|
||||
function b(&$a) {
|
||||
$this->a = &$a;
|
||||
}
|
||||
|
||||
function echoValue() {
|
||||
echo "<br>","class ",get_class($this),': ',$this->a->value;
|
||||
echo "<br>","class ",get_class($this),': ',$this->a->value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// try to undestand why using a simple copy here would yield
|
||||
// in an undesired result in the *-marked line
|
||||
$a =& new a(10);
|
||||
$a =& new a(10);
|
||||
$a->createRef();
|
||||
|
||||
$a->echoValue();
|
||||
|
@ -361,8 +362,8 @@ class b: 11
|
|||
class b: 11
|
||||
*/
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
</informalexample>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue