3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @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 ClassReflection($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()); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Optional parameter $two declared before required parameter $class is implicitly treated as a required parameter in /in/aYGZD on line 150 Deprecated: Optional parameter $three declared before required parameter $class is implicitly treated as a required parameter in /in/aYGZD on line 150 Deprecated: Optional parameter $string declared before required parameter $class is implicitly treated as a required parameter in /in/aYGZD on line 150 Deprecated: Optional parameter $null declared before required parameter $class is implicitly treated as a required parameter in /in/aYGZD on line 150 Deprecated: Optional parameter $int declared before required parameter $class is implicitly treated as a required parameter in /in/aYGZD on line 150 Deprecated: Optional parameter $bool declared before required parameter $class is implicitly treated as a required parameter in /in/aYGZD on line 150 Deprecated: Return type of ParameterReflection::getDeclaringFunction($reflectionClass = null) should either be compatible with ReflectionParameter::getDeclaringFunction(): ReflectionFunctionAbstract, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/aYGZD on line 51 Deprecated: Return type of ParameterReflection::getDeclaringClass() should either be compatible with ReflectionParameter::getDeclaringClass(): ?ReflectionClass, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/aYGZD on line 19 Deprecated: Return type of ParameterReflection::getClass() should either be compatible with ReflectionParameter::getClass(): ?ReflectionClass, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/aYGZD on line 33 Deprecated: Return type of ParameterReflection::getType() should either be compatible with ReflectionParameter::getType(): ?ReflectionType, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/aYGZD on line 69 Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/aYGZD on line 75 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/aYGZD on line 35 Fatal error: Uncaught Error: Class "ClassReflection" not found in /in/aYGZD:22 Stack trace: #0 /in/aYGZD(55): ParameterReflection->getDeclaringClass() #1 /in/aYGZD(79): ParameterReflection->getDeclaringFunction() #2 /in/aYGZD(189): ParameterReflection->getType() #3 {main} thrown in /in/aYGZD on line 22
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Deprecated: Required parameter $empty follows optional parameter $two in /in/aYGZD on line 150 Deprecated: Required parameter $array follows optional parameter $two in /in/aYGZD on line 150 Deprecated: Required parameter $class follows optional parameter $two in /in/aYGZD on line 150 Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/aYGZD on line 75 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/aYGZD on line 35 Fatal error: Uncaught Error: Class "ClassReflection" not found in /in/aYGZD:22 Stack trace: #0 /in/aYGZD(55): ParameterReflection->getDeclaringClass() #1 /in/aYGZD(79): ParameterReflection->getDeclaringFunction() #2 /in/aYGZD(189): ParameterReflection->getType() #3 {main} thrown in /in/aYGZD on line 22
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Class 'ClassReflection' not found in /in/aYGZD:22 Stack trace: #0 /in/aYGZD(55): ParameterReflection->getDeclaringClass() #1 /in/aYGZD(79): ParameterReflection->getDeclaringFunction() #2 /in/aYGZD(189): ParameterReflection->getType() #3 {main} thrown in /in/aYGZD on line 22
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Fatal error: Class 'ClassReflection' not found in /in/aYGZD on line 22
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aYGZD on line 54 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aYGZD on line 77 Fatal error: Class 'ClassReflection' not found in /in/aYGZD on line 22
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aYGZD on line 54 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aYGZD on line 77 Fatal error: Call to undefined method ReflectionParameter::getdeclaringfunction() in /in/aYGZD on line 53
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aYGZD on line 54 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aYGZD on line 77 Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/aYGZD on line 150
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/aYGZD on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/aYGZD on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/aYGZD on line 12
Process exited with code 255.

preferences:
241.7 ms | 401 KiB | 316 Q