Re: Does ReflectionMethod::setAccessible() do anything?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 16, 2010 at 6:37 PM, David Harkness
<david.h@xxxxxxxxxxxxxxxxx>wrote:

> According to the manual page for setAccessible() [1] the feature is
> available with 5.3.2, and I'm running
>
>    5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:49:46)
>
> so I should be good to go. However, even the simplest test to make a
> protected or private method accessible fails.
>
>    php > class Foo { protected function bar() { echo "foobar\n"; } }
>    php > $m = new ReflectionMethod('Foo', 'bar');
>    php > $m->setAccessible(true);
>    php > $foo = new Foo();
>    php > $foo->bar();


you just have to invoke the function from the context of the
ReflectionMethod instance

<?php
class Foo { protected function bar() { echo "foobar\n"; } }
$m = new ReflectionMethod('Foo', 'bar');
$m->setAccessible(true);
$m->invokeArgs(new Foo(), array());
?>

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux