PHP code example of php-di / phpdoc-reader
1. Go to this page and download the library: Download php-di/phpdoc-reader 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/ */
php-di / phpdoc-reader example snippets
use My\Cache\Backend;
class Cache
{
/**
* @var Backend
*/
protected $backend;
/**
* @param Backend $backend
*/
public function __construct($backend)
{
}
}
$reader = new PhpDocReader();
// Read a property type (@var phpdoc)
$property = new ReflectionProperty($className, $propertyName);
$propertyClass = $reader->getPropertyClass($property);
// Read a parameter type (@param phpdoc)
$parameter = new ReflectionParameter([$className, $methodName], $parameterName);
$parameterClass = $reader->getParameterClass($parameter);