|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60604 ReflectionMethod::setAccessible doesn't work with methods from traits
Submitted: 2011-12-24 14:52 UTC Modified: 2011-12-24 15:18 UTC
From: php at mohiva dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.4.0RC3 OS: Gentoo linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php at mohiva dot com
New email:
PHP Version: OS:


 [2011-12-24 14:52 UTC] php at mohiva dot com
The method ReflectionMethod::setAccessible doesn't change the accessibility of a private method defined in a trait.

Test script:

trait Foo {
	private function foo() {}

class Bar {
	use Foo;

$bar = new Bar();
$method = new ReflectionMethod('Bar', 'foo');


Expected result:
The method foo should be callable.

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-24 15:18 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

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!

 [2011-12-24 15:18 UTC]
-Status: Open +Status: Bogus
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 22 12:01:30 2024 UTC