3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestSampleClass { } class MethodReflection extends ReflectionMethod { protected $annotations = null; public function getDocBlock() { if ('' == $this->getDocComment()) { return false; } $instance = new DocBlockReflection($this); return $instance; } public function getAnnotations(AnnotationManager $annotationManager) { if (($docComment = $this->getDocComment()) == '') { return false; } if (!$this->annotations) { $cachingFileScanner = new CachingFileScanner($this->getFileName()); $nameInformation = $cachingFileScanner->getClassNameInformation($this->getDeclaringClass()->getName()); $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation); } return $this->annotations; } public function getDeclaringClass() { $phpReflection = parent::getDeclaringClass(); $zendReflection = new ClassReflection($phpReflection->getName()); unset($phpReflection); return $zendReflection; } public function getParameters() { $phpReflections = parent::getParameters(); $zendReflections = array(); while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { $instance = new ParameterReflection(array($this->getDeclaringClass()->getName(), $this->getName()), $phpReflection->getName()); $zendReflections[] = $instance; unset($phpReflection); } unset($phpReflections); return $zendReflections; } } 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 ClassReflection($phpReflection->getName()); unset($phpReflection); return $zendReflection; } public function getDeclaringFunction($reflectionClass = null) { $phpReflection = parent::getDeclaringFunction(); if ($phpReflection instanceof ReflectionMethod) { $zendReflection = new MethodReflection($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; } }*/ 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; } } 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, $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'; } } $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 git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of MethodReflection::getDeclaringClass() should either be compatible with ReflectionMethod::getDeclaringClass(): ReflectionClass, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/91vem on line 33 Deprecated: Return type of MethodReflection::getParameters() should either be compatible with ReflectionFunctionAbstract::getParameters(): array, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/91vem on line 40 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/91vem on line 77 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/91vem on line 58 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/91vem on line 66 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/91vem on line 89 Deprecated: Optional parameter $two declared before required parameter $class is implicitly treated as a required parameter in /in/91vem on line 135 Deprecated: Optional parameter $three declared before required parameter $class is implicitly treated as a required parameter in /in/91vem on line 135 Deprecated: Optional parameter $string declared before required parameter $class is implicitly treated as a required parameter in /in/91vem on line 135 Deprecated: Optional parameter $null declared before required parameter $class is implicitly treated as a required parameter in /in/91vem on line 135 Deprecated: Optional parameter $int declared before required parameter $class is implicitly treated as a required parameter in /in/91vem on line 135 Deprecated: Optional parameter $bool declared before required parameter $class is implicitly treated as a required parameter in /in/91vem on line 135 Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/91vem on line 68 NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/91vem on line 68 NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/91vem on line 68 NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/91vem on line 68 NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/91vem on line 68 NULL Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 string(5) "array" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 string(5) "array" Deprecated: Method ReflectionParameter::isArray() is deprecated in /in/91vem on line 95 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/91vem on line 68 Fatal error: Uncaught Error: Class "ClassReflection" not found in /in/91vem:72 Stack trace: #0 /in/91vem(97): ParameterReflection->getClass() #1 /in/91vem(160): ParameterReflection->getType() #2 {main} thrown in /in/91vem on line 72
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.04 ms | 409 KiB | 8 Q