编程语言
首页 > 编程语言> > PHP 笔记

PHP 笔记

作者:互联网

1.PHP反射


  exp:

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

class Test
{
    private $c = 1;
    public function a($id)
    {
        echo 'ok a'.$id;
    }    

    private function b($id = 10018){
        echo 'ok b'.$id;
    }
}

$testClass = new ReflectionClass('Test');
$instance  = $testClass->newInstance();
$method = $testClass->getmethod('b');
$method->setAccessible(true);
$method->invoke($instance, 3);
$instance->a(1);
var_dump($testClass->getProperty('c'));

 

标签:getProperty,dump,testClass,笔记,instance,PHP,method
来源: https://www.cnblogs.com/yu-mi/p/15103329.html