<?php require_once "fullshop.php"; require_once "business/ShopProduct3.php"; class ReflectionUtil { static function getClassSource(ReflectionClass $class) { $path = $class->getFileName(); $lines = @file($path); $from = $class->getStartLine(); $to = $class->getEndLine(); $len = $to - $from + 1; return implode(array_slice($lines, $from - 1, $len)); } } print ReflectionUtil::getClassSource(new ReflectionClass('CdProduct')); print ReflectionUtil::getClassSource(new ReflectionClass('business\\ShopProduct3'));
$path = $method->getFileName(); // получаем путь к файлу $lines = @file($path); // получаем массив с кодом $from = $method->getStartLine(); // получаем строку где начинается нужный код $to = $method->getEndLine(); //получаем строку где заканчивается нужный код $len = $to - $from + 1; // получаем длинну return implode(array_slice($lines, $from - 1, $len)); // обрезаем массив, и переводим в строку } } $prod_class = new ReflectionClass("CDProduct"); print ReflectionUtil::getClassSource($prod_class); echo "<hr>"; //--------------------------------------------------------------------------------- // исследование методов function methodData(ReflectionMethod $method) { $details = ""; $name = $method->getName(); if ($method->isUserDefined()) { $details .= "{$name} -- метод определён пользователем<br>"; } if ($method->isInternal()) { $details .= "{$name} -- внутренний метод<br>"; } if ($method->isAbstract()) { $details .= "{$name} -- абстрактный метод<br>";
} } class ReflectionUtil { static function getClassSource(ReflectionClass $class) { $path = $class->getFilename(); $lines = @file($path); $from = $class->getStartLine(); $to = $class->getEndLine(); $len = $to - $from + 1; return implode(array_slice($lines, $from - 1, $len)); } } echo "<pre>"; print ReflectionUtil::getClassSource(new ReflectionClass("returns")); exit; function classData(ReflectionClass $class) { $details = ""; $name = $class->getName(); if ($class->isUserDefined()) { $details .= "{$name} is user defined \n"; } if ($class->isInternal()) { $details .= "{$name} is built-in\n"; } if ($class->isInternal()) { $details .= "{$name} is interface \n"; } if ($class->isAbstract()) {