3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 = null) { return 'mixedValue'; } } $tests = array( array('one', null), array('two', null), ); foreach($tests as $test) { $param = new ParameterReflection(array('TestSampleClass5', 'doSomething'), $test[0]); var_dump($param->getType()); }
Output for 7.0.0 - 7.1.0
bool(false) NULL Fatal error: Uncaught ReflectionException: The parameter specified by its name could not be found in /in/diQrX:102 Stack trace: #0 /in/diQrX(102): ReflectionParameter->__construct(Array, 'two') #1 {main} thrown in /in/diQrX on line 102
Process exited with code 255.
Output for hhvm-3.12.0
bool(false) NULL Fatal error: Uncaught exception 'ReflectionException' with message 'The parameter specified by its name could not be found' in /in/diQrX:-1 Stack trace: #0 /in/diQrX(-1): ReflectionParameter->__construct() #1 {main}
Process exited with code 255.
Output for hhvm-3.10.0
bool(false) NULL Fatal error: Uncaught exception 'ReflectionException' with message 'The parameter specified by its name could not be found' in /in/diQrX:102 Stack trace: #0 /in/diQrX(102): ReflectionParameter->__construct() #1 {main}
Process exited with code 255.
Output for 5.1.0 - 5.6.28
bool(false) NULL Fatal error: Uncaught exception 'ReflectionException' with message 'The parameter specified by its name could not be found' in /in/diQrX:102 Stack trace: #0 /in/diQrX(102): ReflectionParameter->__construct(Array, 'two') #1 {main} thrown in /in/diQrX on line 102
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined method ParameterReflection::isArray() in /in/diQrX on line 46
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/diQrX on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/diQrX 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/diQrX on line 8
Process exited with code 255.