3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestSampleClass { } class ParameterReflection extends ReflectionParameter { protected $isFromMethod = false; public function getDeclaringClass() { $phpReflection = parent::getDeclaringClass(); $zendReflection = new ReflectionClass($phpReflection->getName()); unset($phpReflection); return $zendReflection; } public function getClass() { $phpReflection = parent::getClass(); if ($phpReflection == null) { return null; } $zendReflection = new ReflectionClass($phpReflection->getName()); unset($phpReflection); return $zendReflection; } 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; } 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; } }*/ var_dump($this->isDefaultValueAvailable()); if ($this->isDefaultValueAvailable() && $checkDefault) { if ($type === null) { $value = $this->getDefaultValue(); var_dump($value); $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; } } class TestSampleClass5 { /** * @param int $one Description for one * @param int Description for two * @param string $three Description for three * which spans multiple lines */ public function doSomething($one, $empty, array $array, TestSampleClass $class, $two = 2, $three = 'three', $string = 'somestring', $null = null, $int = 1, $bool = true, array $arrayOrNull = null, TestSampleClass $classOrNull = null) { 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
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/1iR5X on line 28 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/1iR5X on line 9 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/1iR5X on line 17 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/1iR5X on line 40 Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(false) NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) int(2) string(3) "int" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) string(5) "three" string(6) "string" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(false) NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) string(10) "somestring" string(6) "string" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) NULL string(4) "null" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) int(1) string(3) "int" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) bool(true) string(4) "bool" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 bool(false) string(5) "array" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 bool(true) string(10) "array|null" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(false) string(15) "TestSampleClass" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) string(20) "TestSampleClass|null"
Output for 8.0.0 - 8.0.30
Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(false) NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) int(2) string(3) "int" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) string(5) "three" string(6) "string" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(false) NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) string(10) "somestring" string(6) "string" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) NULL string(4) "null" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) int(1) string(3) "int" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) bool(true) string(4) "bool" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 bool(false) string(5) "array" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 bool(true) string(10) "array|null" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(false) string(15) "TestSampleClass" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/1iR5X on line 46 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/1iR5X on line 19 bool(true) string(20) "TestSampleClass|null"
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
bool(false) NULL bool(true) int(2) string(3) "int" bool(true) string(5) "three" string(6) "string" bool(false) NULL bool(true) string(10) "somestring" string(6) "string" bool(true) NULL string(4) "null" bool(true) int(1) string(3) "int" bool(true) bool(true) string(4) "bool" bool(false) string(5) "array" bool(true) string(10) "array|null" bool(false) string(15) "TestSampleClass" bool(true) string(20) "TestSampleClass|null"
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/1iR5X on line 89
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/1iR5X on line 8
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/1iR5X on line 8
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/1iR5X on line 8
Process exited with code 255.

preferences:
253.34 ms | 401 KiB | 359 Q