|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81662 Private functions are invokable without need to use "setAccessible".
Submitted: 2021-11-26 15:16 UTC Modified: 2021-11-26 20:04 UTC
From: werlos at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 8.1.0 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: werlos at gmail dot com
New email:
PHP Version: OS:


 [2021-11-26 15:16 UTC] werlos at gmail dot com
Prior to PHP 8.1 to invoke private method with ReflectionMethod calling "setAccessible" with "true" was needed.

Test script:

class Foo {
    private function bar() { return 42; }

$foo = new Foo();

$reflection = new \ReflectionMethod($foo, 'bar');

echo $reflection->invoke($foo);

Expected result:
The need of calling "setAccessible": "$reflection->setAccessible(true);".


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-26 15:21 UTC]
-Status: Open +Status: Not a bug
 [2021-11-26 15:21 UTC]
Yes, this is no longer needed:
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 02 06:01:27 2023 UTC