PHP code example of reflective / reflection

1. Go to this page and download the library: Download reflective/reflection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reflective / reflection example snippets


use Reflective\Reflection\ReflectionClass;

$ref = new ReflectionClass(AccountController::class);
dd(
    $ref->getDeclaredMethods(),
    $ref->getDeclaredMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED),
);

use Reflective\Reflection\ReflectionClass;

$ref = new ReflectionClass(AccountController::class);
dd(
    $ref->getParentClasses(),
    $ref->getParentClasses(BaseController::class),
    $ref->getParentClasses(BaseController::class, ReflectionClass::IS_INSTANCEOF),
);

use Reflective\Reflection\ReflectionParentClass;

$ref = new ReflectionParentClass(AccountController::class);
dd(
    $ref->getParentClasses(),
    $ref->getParentClasses(BaseController::class),
    $ref->getParentClasses(BaseController::class, ReflectionParentClass::IS_INSTANCEOF),
);