note 100920 added to language.oop5.visibility

From: Date: Mon, 15 Nov 2010 12:41:34 +0000
Subject: note 100920 added to language.oop5.visibility
Groups: php.notes 
Request: Send a blank email to php-notes+get-174036@lists.php.net to get a copy of this message
This is in response to ryan lange below. I suspect this is not a quirk. The docs state: "Members declared as private may only be accessed by the class that defines the member." This means ChildClass2 *never* accesses the variable defined in the parent class, but always accesses its own local values. Likewise, ParentClass can't access private vars set in ChildClass2. If you want this behaviour, then you should use the protected keyword, not private. To try explain what's happening: ChildClass2 sets $this->foo, but in reality it's creating a localised variable on the fly (ChildClass2::foo, rather than setting ParentClass::foo). I can't find a reference to it, but I would hazard a guess that vars created in this fashion are private by default. Also ParentClass never sets ParentClass::foo to "foo", because ParentClass::__construct() is never called (only ChildClass2's construct is called). This is why, when you call $child2->foo() you get nothing back, because the ParentClass can't access the var ChildClass2::foo, and ParentClass::foo was never set to a value. ---- Server IP: 69.147.83.197 Probable Submitter: 87.81.122.105 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.visibility.php Edit -- https://master.php.net/note/edit/100920 Del: integrated -- https://master.php.net/note/delete/100920/integrated Del: useless -- https://master.php.net/note/delete/100920/useless Del: bad code -- https://master.php.net/note/delete/100920/bad+code Del: spam -- https://master.php.net/note/delete/100920/spam Del: non-english -- https://master.php.net/note/delete/100920/non-english Del: in docs -- https://master.php.net/note/delete/100920/in+docs Del: other reasons-- https://master.php.net/note/delete/100920 Reject -- https://master.php.net/note/reject/100920 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174036) next »