note 103920 added to reflectionmethod.setaccessible

From: Date: Wed, 11 May 2011 10:21:25 +0000
Subject: note 103920 added to reflectionmethod.setaccessible
Groups: php.notes 
Request: Send a blank email to php-notes+get-179602@lists.php.net to get a copy of this message
This is handy for accessing private methods but remember that things are normally private for a reason! Unit Testing is one (debatable) use case for this. Example: <?php class Foo { private function myPrivateMethod() { return 7; } } $method = new ReflectionMethod('Foo', 'myPrivateMethod'); $method->setAccessible(true); echo $method->invoke(new Foo); // echos "7" ?> This works nicely with PHPUnit: http://php.net/manual/en/reflectionmethod.setaccessible.php ---- Server IP: 69.147.83.197 Probable Submitter: 109.104.100.34 ---- Manual Page -- http://www.php.net/manual/en/reflectionmethod.setaccessible.php Edit -- https://master.php.net/note/edit/103920 Del: integrated -- https://master.php.net/note/delete/103920/integrated Del: useless -- https://master.php.net/note/delete/103920/useless Del: bad code -- https://master.php.net/note/delete/103920/bad+code Del: spam -- https://master.php.net/note/delete/103920/spam Del: non-english -- https://master.php.net/note/delete/103920/non-english Del: in docs -- https://master.php.net/note/delete/103920/in+docs Del: other reasons-- https://master.php.net/note/delete/103920 Reject -- https://master.php.net/note/reject/103920 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179602) next »