note 88009 added to language.oop5.reflection

From: Date: Tue, 06 Jan 2009 04:19:42 +0000
Subject: note 88009 added to language.oop5.reflection
Groups: php.notes 
Request: Send a blank email to php-notes+get-148872@lists.php.net to get a copy of this message
With PHP 5.3 protected or private properties are easy to access with setAccessible(). However, it's sometimes needed (e.g. Unit Tests) and here is a workaround for getValue(): <?php $class = new ReflectionClass('SomeClass'); $props = $class->getProperties(); // $propsStatic = $class->getStaticProperties(); $myPrivatePropertyValue = $props['aPrivateProperty']; ?> Note that it wont work if you access the property directly with getProperty(). ---- Server IP: 69.147.83.197 Probable Submitter: 84.72.100.202 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.reflection.php Edit -- https://master.php.net/note/edit/88009 Del: integrated -- https://master.php.net/note/delete/88009/integrated Del: useless -- https://master.php.net/note/delete/88009/useless Del: bad code -- https://master.php.net/note/delete/88009/bad+code Del: spam -- https://master.php.net/note/delete/88009/spam Del: non-english -- https://master.php.net/note/delete/88009/non-english Del: in docs -- https://master.php.net/note/delete/88009/in+docs Del: other reasons-- https://master.php.net/note/delete/88009 Reject -- https://master.php.net/note/reject/88009 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148872) next »