3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestSampleClass { } /** * @category Zend * @package Zend_Reflection */ class ParameterReflection extends ReflectionParameter { /** * @var bool */ protected $isFromMethod = false; /** * Get declaring class reflection object * * @return ClassReflection */ public function getDeclaringClass() { $phpReflection = parent::getDeclaringClass(); $zendReflection = new ReflectionClass($phpReflection->getName()); unset($phpReflection); return $zendReflection; } /** * Get class reflection object * * @return ClassReflection */ public function getClass() { $phpReflection = parent::getClass(); if ($phpReflection == null) { return null; } $zendReflection = new ClassReflection($phpReflection->getName()); unset($phpReflection); return $zendReflection; } /** * Get declaring function reflection object * * @param string $reflectionClass Reflection class to use * @return FunctionReflection|MethodReflection */ public function getDeclaringFunction($reflectionClass = null) { $phpReflection = parent::getDeclaringFunction(); if ($phpReflection instanceof ReflectionMethod) { $zendReflection = new ReflectionMethod($this->getDeclaringClass()->getName(), $phpReflection->getName()); } else { $zendReflection = new ReflectionFunction($phpReflection->getName()); } unset($phpReflection); return $zendReflection; } /** * Get parameter type * * @return string */ public function getType() { $type = null; $checkDefault = true; if ($this->isArray()) { $type = 'array'; } elseif (($class = $this->getClass()) instanceof ReflectionClass) { $type = $class->getName(); } elseif ($docBlock = $this->getDeclaringFunction()->getDocBlock()) { $params = $docBlock->getTags('param'); if (isset($params[$this->getPosition()])) { $type = $params[$this->getPosition()]->getType(); $checkDefault = false; } } if ($this->isDefaultValueAvailable() && $checkDefault) { if ($type === null) { $value = $this->getDefaultValue(); $type = strtolower(gettype($value)); switch ($type) { case 'boolean' : $type = 'bool'; break; case 'integer' : $type = 'int'; break; } } else { if ($this->getDefaultValue() === null) { $type .= '|null'; } } } return $type; } public function toString() { return parent::__toString(); } public function __toString() { return parent::__toString(); } } /** * TestSampleClass5 DocBlock Short Desc * * This is a long description for * the docblock of this class, it * should be longer than 3 lines. * It indeed is longer than 3 lines * now. * * @author Ralph Schindler <ralph.schindler@zend.com> * @method test() * @property $test */ class TestSampleClass5 { /** * Method ShortDescription * * Method LongDescription * This is a long description for * the docblock of this class, it * should be longer than 3 lines. * It indeed is longer than 3 lines * now. * * @param int $one Description for one * @param int Description for two * @param string $three Description for three * which spans multiple lines * @return mixed Some return descr */ public function doSomething($one, $two = 2, $three = 'three', $empty, $string = 'somestring', $null = null, $int = 1, $bool = true, array $array, array $arrayOrNull = null, TestSampleClass $class, TestSampleClass $classOrNull = null) { return 'mixedValue'; } /** * Method ShortDescription * * @param int $one Description for one * @param int Description for two * @param string $three Description for three * which spans multiple lines * @return int */ public function doSomethingElse($one, $two = 2, $three = 'three') { return 'mixedValue'; } } $tests = array( array('one', 'int'), array('two', 'int'), array('three', 'string'), array('empty', null), array('string', 'string'), array('null', 'null'), array('int', 'int'), array('bool', 'bool'), array('array', 'array'), array('arrayOrNull','array|null'), array('class', 'ZendTest\Code\Reflection\TestAsset\TestSampleClass'), array('classOrNull','ZendTest\Code\Reflection\TestAsset\TestSampleClass|null'), ); foreach($tests as $test) { $param = new ParameterReflection(array('TestSampleClass5', 'doSomething'), $test[0]); var_dump($param->getType()); }

preferences:
39.92 ms | 402 KiB | 5 Q