note 111409 added to language.references.whatdo

From: Date: Sun, 17 Feb 2013 18:05:54 +0000
Subject: note 111409 added to language.references.whatdo
Groups: php.notes 
Request: Send a blank email to php-notes+get-193662@lists.php.net to get a copy of this message
This appears to be the hidden behavior: When a class function has the same name as the class, it seems to be implicitly called when an object of the class is created. For instance, you may take a look at the naming of the function "reftest()": it is in the class "reftest". The behavior can be tested as follows: <?php class reftest { public $a = 1; public $c = 1; public function reftest1() { $b =& $this->a; $b++; } public function reftest2() { $d =& $this->c; $d++; } public function reftest() { echo "REFTEST() called here!\n"; } } $reference = new reftest(); /*You must notice the above will also implicitly call reference->reftest()*/ $reference->reftest1(); $reference->reftest2(); echo $reference->a."\n"; //Echoes 2, not 3 as previously noticed. echo $reference->c."\n"; //Echoes 2. ?> The above outputs: REFTEST() called here! 2 2 Notice that reftest() appears to be called (though no explicit call to it was made)! ---- Server IP: 69.147.83.199 Probable Submitter: 209.65.60.235 ---- Manual Page -- http://php.net/manual/en/language.references.whatdo.php Edit -- https://master.php.net/note/edit/111409 Del: integrated -- https://master.php.net/note/delete/111409/integrated Del: useless -- https://master.php.net/note/delete/111409/useless Del: bad code -- https://master.php.net/note/delete/111409/bad+code Del: spam -- https://master.php.net/note/delete/111409/spam Del: non-english -- https://master.php.net/note/delete/111409/non-english Del: in docs -- https://master.php.net/note/delete/111409/in+docs Del: other reasons-- https://master.php.net/note/delete/111409 Reject -- https://master.php.net/note/reject/111409 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193662) next »