PHP code example of rikudou / reflection-file
1. Go to this page and download the library: Download rikudou/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/ */
rikudou / reflection-file example snippets
use Rikudou\ReflectionFile;
use Rikudou\Exception\ReflectionException;
try {
$reflection = new ReflectionFile("/path/to/file.php");
} catch (ReflectionException $exception) {
var_dump("The file does not exist!");
}
// true if the file contains a class
$reflection->containsClass();
// true if the file contains any namespace
$reflection->containsNamespace();
// true if the file contains any inline html, e.g. content that is not php
$reflection->containsInlineHtml();
// true if the file contains any php code
$reflection->containsPhpCode();
// true if the file contains echo or print statements
$reflection->printsOutput();
// true if the file contains functions (not methods)
$reflection->containsFunctions();
try {
// returns the namespace as a string, throws exception if the
// file does not contain a namespace
$reflection->getNamespace();
} catch (ReflectionException $exception) {
var_dump("The class does not contain a namespace!");
}
// the previous example can be rewritten as follows
if($reflection->containsNamespace()) {
$reflection->getNamespace();
}
try {
// returns instance of \ReflectionClass if the file contains a class
// otherwise throws an exception
$reflection->getClass();
} catch (ReflectionException $exception) {
var_dump("The class does not contain a class!");
}
// returns array with \ReflectionFunction instances
// can throw exception if the functions could not be found
// which happnes when the file is not