PHP code example of psychob / reflection-file

1. Go to this page and download the library: Download psychob/reflection-file 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/ */

    

psychob / reflection-file example snippets



use PsychoB\ReflectionFile\ReflectionFile;

$reflection = new ReflectionFile('path/to/your/file.php');

// Get all class names
$classes = $reflection->getNamesOfClasses();

// Get all interfaces
$interfaces = $reflection->getNamesOfInterfaces();

// Get all traits
$traits = $reflection->getNamesOfTraits();

// Get namespace information
$namespace = $reflection->getFirstNameOfNamespace();


use PsychoB\ReflectionFile\ReflectionFile;

// Defer both parsing and loading until needed
$reflection = new ReflectionFile(
    'path/to/file.php',
    deferParsing: true,
    deferLoading: true
);

// Only parse when needed
$classes = $reflection->getNamesOfClasses(); // Triggers parsing

// Manual control over loading
$reflection->load(); // Explicitly load the file

$namespaces = $reflection->getNamesOfNamespaces();
$firstNamespace = $reflection->getFirstNameOfNamespace();

$classes = $reflection->getNamesOfClasses();
$abstractClasses = $reflection->getNamesOfAbstractClasses();

$interfaces = $reflection->getNamesOfInterfaces();
$traits = $reflection->getNamesOfTraits();
$functions = $reflection->getNamesOfFunctions();
$enums = $reflection->getNamesOfEnums();