本文整理汇总了PHP中ReflectionParameter::__toString方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::__toString方法的具体用法?PHP ReflectionParameter::__toString怎么用?PHP ReflectionParameter::__toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::__toString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(ReflectionParameter $param)
{
if (method_exists('ReflectionParameter', 'getType')) {
if ($type = $param->getType()) {
$this->type_hint = (string) $type;
}
} else {
if ($param->isArray()) {
$this->type_hint = 'array';
} else {
try {
if ($this->type_hint = $param->getClass()) {
$this->type_hint = $this->type_hint->name;
}
} catch (ReflectionException $e) {
preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches);
$this->type_hint = isset($matches[1]) ? $matches[1] : '';
}
}
}
$this->reference = $param->isPassedByReference();
$this->position = $param->getPosition();
$this->name = $param->getName();
if ($param->isDefaultValueAvailable()) {
$this->default = var_export($param->getDefaultValue(), true);
}
}
示例2: __toString
/**
* Returns a string representation
* @return string
*/
public function __toString()
{
if ($this->parameter) {
return $this->parameter->__toString();
} else {
return parent::__toString();
}
}
示例3: __toString
/**
* Representation of the object
*
* If an exception is caught, its message is returned instead of the
* original result (but it is not thrown ahead).
*
* @return string
*/
public function __toString()
{
try {
return parent::__toString() . ' with user value { ' . ReflectionValue::export($this->value, true) . ' }';
} catch (\Exception $e) {
return $e->__toString();
}
}
示例4: getParameterType
/**
* Returns the type of the parameter. In case the parameter has no type (e.g. primitive) the
* method returns null.
*
* @param ReflectionParameter $param
* @return string
*/
public static function getParameterType(ReflectionParameter $param)
{
$matches = array();
preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches);
if (isset($matches[1])) {
return $matches[1];
} else {
return null;
}
}
示例5: getType
/**
* @return ReflectionTypeInterface|null
*/
public function getType()
{
if (PHP_MAJOR_VERSION >= 7) {
if ($this->hasType()) {
return new ReflectionType($this->parameter->getType());
} else {
return null;
}
}
$type = null;
preg_match('/\\[\\s<\\w+?>\\s([\\\\\\w]+)/', $this->parameter->__toString(), $matches);
if (isset($matches[1])) {
if (in_array($matches[1], ReflectionTypeInterface::NON_QUALIFIED_TYPES, true)) {
$name = $matches[1];
} else {
$name = '\\' . $matches[1];
}
$type = new ReflectionTypePolyFill($name, $this->parameter->allowsNull());
}
return $type;
}
示例6: getArgumentType
/**
* Gets the argument data type
*
* Returns same data types as PHP's gettype() method:
* 'boolean', 'integer', 'double', 'string', 'array',
* 'object', 'resource', 'NULL', 'unknown type'
*
* @param \ReflectionParameter $argument Argument's ReflectionParameter instance
* @return string
*/
private function getArgumentType(\ReflectionParameter $argument)
{
if ($argument->isArray()) {
return 'array';
}
// check to see if it's a typehinted class
$regex = '/^.*\\<\\w+?> ([\\w\\\\]+?) +.*$/';
preg_match($regex, $argument->__toString(), $matches);
if (isset($matches[1])) {
return 'object';
}
if ($argument->isOptional()) {
return gettype($argument->getDefaultValue());
}
return null;
}
示例7: getParameterClassName
/**
* A static version of `ReflectionParameter::getName()` that doesn't require the parameter class to be loaded.
*
* This prevents fatal errors when a parameter uses a class name for type hinting but the class is not loaded.
*
* @param \ReflectionParameter $param The parameter reflection object
* @return string The name of the parameter's type hinted object, if there is one.
*/
protected static function getParameterClassName(\ReflectionParameter $param)
{
preg_match('/\\[\\s\\<\\w+?>\\s([a-zA-Z0-9_\\\\]+)/s', $param->__toString(), $matches);
return isset($matches[1]) ? $matches[1] : null;
}
示例8: getParameterType
public static final function getParameterType(ReflectionParameter $param)
{
preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches);
return isset($matches[1]) ? $matches[1] : null;
}
示例9: getClassName
protected function getClassName(ReflectionParameter $param)
{
preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches);
return isset($matches[1]) ? $matches[1] : null;
}
示例10: getParameterClassName
protected function getParameterClassName(\ReflectionParameter $param)
{
preg_match('/> ([^ ]+) /', $param->__toString(), $matches);
return !in_array($matches[1], ['$' . $param->getName(), 'array'], true) ? $matches[1] : null;
}
示例11: getParamClassName
private function getParamClassName(\ReflectionParameter $param)
{
preg_match('/\\[\\s\\<\\w+?>\\s([\\w\\\\]+)/s', $param->__toString(), $matches);
return isset($matches[1]) ? $matches[1] : null;
}
示例12: foo
<?php
function foo(array $x = array('a', 'b'))
{
}
$r = new ReflectionParameter('foo', 0);
echo $r->__toString();
示例13: getClassName
private static function getClassName(\ReflectionParameter $param)
{
preg_match('/(\\w+)\\s\\$\\w+\\s\\]$/s', $param->__toString(), $matches);
return isset($matches[1]) ? $matches[1] : null;
}