php.net |  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
8 + 2 = ?
Subscribe to this entry?

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

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

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);".


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-26 15:21 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-11-26 15:21 UTC] nikic@php.net
Yes, this is no longer needed: https://wiki.php.net/rfc/make-reflection-setaccessible-no-op
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 01:01:28 2024 UTC