Edit report at https://bugs.php.net/bug.php?id=60604&edit=1

 ID:                 60604
 Updated by:         g...@php.net
 Reported by:        php at mohiva dot com
 Summary:            ReflectionMethod::setAccessible doesn't work with
                     methods from traits
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            Reflection related
 Operating System:   Gentoo linux
 PHP Version:        5.4.0RC3
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Hi, your last line has the mistake.

Try '$method->invoke($bar);' instead, and at least on my machine it works.

The reflection mirror knows about your change, the original class is left 
unchanged. And, as with normal classes, you need to use the mirror and invoke() 
to bypass visibility.

Please reopen if I misunderstood something!

Thanks
Stefan


Previous Comments:
------------------------------------------------------------------------
[2011-12-24 14:52:20] php at mohiva dot com

Description:
------------
The method ReflectionMethod::setAccessible doesn't change the accessibility of 
a private method defined in a trait.

Test script:
---------------
<?php

trait Foo {
        
        private function foo() {}
}

class Bar {
        
        use Foo;
}

$bar = new Bar();
$method = new ReflectionMethod('Bar', 'foo');
$method->setAccessible(true);

$bar->foo();


Expected result:
----------------
The method foo should be callable.

Actual result:
--------------
PHP Fatal error:  Call to private method Bar::foo() from context '' in ...


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60604&edit=1

Reply via email to