note 106262 added to language.oop5.basic

From: Date: Sun, 23 Oct 2011 05:07:14 +0000
Subject: note 106262 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-184069@lists.php.net to get a copy of this message
Some thing that may be obvious to the seasoned PHP programmer, but may surprise someone coming over from C++: <?php class Foo { $bar = 'Hi There'; public function Print(){ echo $bar; } } ?> Gives an error saying Print used undefined variable. One has to explicitly use (notice the use of <?php $this->bar ?>): <?php class Foo { $bar = 'Hi There'; public function Print(){ echo this->$bar; } } ?> <?php echo $this->bar; ?> refers to the class member, while using $bar means using an uninitialized variable in the local context of the member function. ---- Server IP: 69.147.83.197 Probable Submitter: 122.172.27.77 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/106262 Del: integrated -- https://master.php.net/note/delete/106262/integrated Del: useless -- https://master.php.net/note/delete/106262/useless Del: bad code -- https://master.php.net/note/delete/106262/bad+code Del: spam -- https://master.php.net/note/delete/106262/spam Del: non-english -- https://master.php.net/note/delete/106262/non-english Del: in docs -- https://master.php.net/note/delete/106262/in+docs Del: other reasons-- https://master.php.net/note/delete/106262 Reject -- https://master.php.net/note/reject/106262 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184069) next »