note 108320 added to language.oop5.properties

From: Date: Tue, 17 Apr 2012 09:16:42 +0000
Subject: note 108320 added to language.oop5.properties
Groups: php.notes 
Request: Send a blank email to php-notes+get-187201@lists.php.net to get a copy of this message
In case this saves anyone any time, I spent ages working out why the following didn't work: class MyClass { private $foo = FALSE; public function __construct() { $this->$foo = TRUE; echo($this->$foo); } } $bar = new MyClass(); giving "Fatal error: Cannot access empty property in ...test_class.php on line 8" The subtle change of removing the $ before accesses of $foo fixes this: class MyClass { private $foo = FALSE; public function __construct() { $this->foo = TRUE; echo($this->foo); } } $bar = new MyClass(); I guess because it's treating $foo like a variable in the first example, so trying to call $this->FALSE (or something along those lines) which makes no sense. It's obvious once you've realised, but there aren't any examples of accessing on this page that show that. ---- Server IP: 69.147.83.197 Probable Submitter: 78.86.200.205 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.properties.php Edit -- https://master.php.net/note/edit/108320 Del: integrated -- https://master.php.net/note/delete/108320/integrated Del: useless -- https://master.php.net/note/delete/108320/useless Del: bad code -- https://master.php.net/note/delete/108320/bad+code Del: spam -- https://master.php.net/note/delete/108320/spam Del: non-english -- https://master.php.net/note/delete/108320/non-english Del: in docs -- https://master.php.net/note/delete/108320/in+docs Del: other reasons-- https://master.php.net/note/delete/108320 Reject -- https://master.php.net/note/reject/108320 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187201) next »