Bug #81662 [Nab]: Private functions are invokable without need to use "setAccessible".

From: Date: Fri, 26 Nov 2021 20:04:44 +0000
Subject: Bug #81662 [Nab]: Private functions are invokable without need to use "setAccessible".
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237999@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81662&edit=1

 ID:                 81662
 Updated by:         cmb@php.net
 Reported by:        werlos at gmail dot com
 Summary:            Private functions are invokable without need to use
                     "setAccessible".
 Status:             Not a bug
 Type:               Bug
 Package:            Reflection related
 Operating System:   linux
 PHP Version:        8.1.0
 Block user comment: N
 Private report:     N

 New Comment:

Documented:
<https://github.com/php/doc-en/commit/7b6a20ed5d1f1bec158b0c57b69bf021a9ed2799>.


Previous Comments:
------------------------------------------------------------------------
[2021-11-26 15:21:43] nikic@php.net

Yes, this is no longer needed: https://wiki.php.net/rfc/make-reflection-setaccessible-no-op

------------------------------------------------------------------------
[2021-11-26 15:16:57] 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);".



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



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


Thread (3 messages)

« previous php.bugs (#237999) next »