array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'reflectionmethod.setaccessible.php', 1 => 'ReflectionMethod::setAccessible', ), 'up' => array ( 0 => 'class.reflectionmethod.php', 1 => 'ReflectionMethod', ), 'prev' => array ( 0 => 'reflectionmethod.ispublic.php', 1 => 'ReflectionMethod::isPublic', ), 'next' => array ( 0 => 'reflectionmethod.tostring.php', 1 => 'ReflectionMethod::__toString', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/reflection/reflectionmethod/setaccessible.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.3.2, PHP 7, PHP 8)
ReflectionMethod::setAccessible — Set method accessibility
Enables invoking of a protected or private method via the ReflectionMethod::invoke() method.
Bilginize: As of PHP 8.1.0, calling this method has no effect; all methods are invokable by default.
Hiçbir değer dönmez.
Örnek 1 Simple Class definition
<?php
class MyClass
{
private function foo()
{
return 'bar';
}
}
$method = new ReflectionMethod("MyClass", "foo");
$method->setAccessible(true);
$obj = new MyClass();
echo $method->invoke($obj);
echo $obj->foo();
?>
Yukarıdaki örnek şuna benzer bir çıktı üretir:
bar Fatal error: Uncaught Error: Call to private method MyClass::foo() from global scope in /in/qdaZS:16