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

From: Date: Fri, 26 Nov 2021 15:21:43 +0000
Subject: Bug #81662 [Opn->Nab]: Private functions are invokable without need to use "setAccessible".
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237997@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:         nikic@php.net
 Reported by:        werlos at gmail dot com
 Summary:            Private functions are invokable without need to use
                     "setAccessible".
-Status:             Open
+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:

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


Previous Comments:
------------------------------------------------------------------------
[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 (#237997) next »