本文整理汇总了PHP中ReflectionObject::isAnonymous方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject::isAnonymous方法的具体用法?PHP ReflectionObject::isAnonymous怎么用?PHP ReflectionObject::isAnonymous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionObject
的用法示例。
在下文中一共展示了ReflectionObject::isAnonymous方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isComparable
public function isComparable(AbstractSnapshot $snapshot)
{
$refl = new \ReflectionObject($snapshot);
return $refl->isAnonymous() || parent::isComparable($snapshot);
}
示例2: _toPhp
/**
* @return string
*/
private static function _toPhp(&$var, &$list = array(), $level = 0, &$line = 1)
{
if (is_float($var)) {
$var = str_replace(',', '.', "{$var}");
return strpos($var, '.') === FALSE ? $var . '.0' : $var;
} elseif (is_bool($var)) {
return $var ? 'TRUE' : 'FALSE';
} elseif (is_string($var) && (preg_match('#[^\\x09\\x20-\\x7E\\xA0-\\x{10FFFF}]#u', $var) || preg_last_error())) {
static $table;
if ($table === NULL) {
foreach (array_merge(range("", ""), range("", "ÿ")) as $ch) {
$table[$ch] = '\\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT);
}
$table['\\'] = '\\\\';
$table["\r"] = '\\r';
$table["\n"] = '\\n';
$table["\t"] = '\\t';
$table['$'] = '\\$';
$table['"'] = '\\"';
}
return '"' . strtr($var, $table) . '"';
} elseif (is_array($var)) {
$space = str_repeat("\t", $level);
static $marker;
if ($marker === NULL) {
$marker = uniqid("", TRUE);
}
if (empty($var)) {
$out = '';
} elseif ($level > self::$maxDepth || isset($var[$marker])) {
return '/* Nesting level too deep or recursive dependency */';
} else {
$out = "\n{$space}";
$outShort = '';
$var[$marker] = TRUE;
$oldLine = $line;
$line++;
$counter = 0;
foreach ($var as $k => &$v) {
if ($k !== $marker) {
$item = ($k === $counter ? '' : self::_toPhp($k, $list, $level + 1, $line) . ' => ') . self::_toPhp($v, $list, $level + 1, $line);
$counter = is_int($k) ? max($k + 1, $counter) : $counter;
$outShort .= ($outShort === '' ? '' : ', ') . $item;
$out .= "\t{$item},\n{$space}";
$line++;
}
}
unset($var[$marker]);
if (strpos($outShort, "\n") === FALSE && strlen($outShort) < self::$maxLength) {
$line = $oldLine;
$out = $outShort;
}
}
return 'array(' . $out . ')';
} elseif ($var instanceof \Closure) {
$rc = new \ReflectionFunction($var);
return "/* Closure defined in file {$rc->getFileName()} on line {$rc->getStartLine()} */";
} elseif (is_object($var)) {
if (PHP_VERSION_ID >= 70000 && ($rc = new \ReflectionObject($var)) && $rc->isAnonymous()) {
return "/* Anonymous class defined in file {$rc->getFileName()} on line {$rc->getStartLine()} */";
}
$arr = (array) $var;
$space = str_repeat("\t", $level);
$class = get_class($var);
$used =& $list[spl_object_hash($var)];
if (empty($arr)) {
$out = '';
} elseif ($used) {
return "/* {$class} dumped on line {$used} */";
} elseif ($level > self::$maxDepth) {
return '/* Nesting level too deep */';
} else {
$out = "\n";
$used = $line;
$line++;
foreach ($arr as $k => &$v) {
if ($k[0] === "") {
$k = substr($k, strrpos($k, "") + 1);
}
$out .= "{$space}\t" . self::_toPhp($k, $list, $level + 1, $line) . ' => ' . self::_toPhp($v, $list, $level + 1, $line) . ",\n";
$line++;
}
$out .= $space;
}
$hash = self::hash($var);
return $class === 'stdClass' ? "(object) /* {$hash} */ array({$out})" : "{$class}::__set_state(/* {$hash} */ array({$out}))";
} elseif (is_resource($var)) {
return '/* resource ' . get_resource_type($var) . ' */';
} else {
$res = var_export($var, TRUE);
$line += substr_count($res, "\n");
return $res;
}
}