- var_dump: documentation ( source)
- strtolower: documentation ( source)
<?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());
}