note 101750 modified in language.references.whatdo by danbrown
| From: | danbrown@php.net | Date: | Sun, 09 Jan 2011 01:32:44 +0000 |
| Subject: | note 101750 modified in language.references.whatdo by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175553@lists.php.net to get a copy of this message | ||
In this example class name is different from its first function and however there is no construction
function. In the end as you guess "a" and "c" are equal. So if there is no
construction function at same time class and its first function names are the same, "a"
and "c" doesn't equal forever. In my opinion php doesn't seek any function for
the construction as long as their names differ from each others.
<?php
class reftest_new
{
public $a = 1;
public $c = 1;
public function reftest()
{
$b =& $this->a;
$b++;
}
public function reftest2()
{
$d =& $this->c;
$d++;
}
}
$reference = new reftest_new();
$reference->reftest();
$reference->reftest2();
echo $reference->a; //Echoes 2.
echo $reference->c; //Echoes 2.
?>
--was--
In this example class name is different from its first function and however there is no construction
function. In the end as you guess "a" and "c" are equal. So if there is no
construction function at same time class and its first function names are the same, "a"
and "c" doesn't equal forever. In my opinion php doesn't seek any function for
the construction as long as their names differ from each others.
class reftest_new
{
public $a = 1;
public $c = 1;
public function reftest()
{
$b =& $this->a;
$b++;
}
public function reftest2()
{
$d =& $this->c;
$d++;
}
}
$reference = new reftest_new();
$reference->reftest();
$reference->reftest2();
echo $reference->a; //Echoes 2.
echo $reference->c; //Echoes 2.
http://php.net/manual/en/language.references.whatdo.php