本文整理汇总了PHP中ReflectionClass::iscloneable方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::iscloneable方法的具体用法?PHP ReflectionClass::iscloneable怎么用?PHP ReflectionClass::iscloneable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::iscloneable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recursive
/**
* Invoke callback recursively for all data types
* @return mixed
* @param $arg mixed
* @param $func callback
* @param $stack array
**/
function recursive($arg, $func, $stack = NULL)
{
if ($stack) {
foreach ($stack as $node) {
if ($arg === $node) {
return $arg;
}
}
} else {
$stack = array();
}
switch (gettype($arg)) {
case 'object':
if (method_exists('ReflectionClass', 'iscloneable')) {
$ref = new ReflectionClass($arg);
if ($ref->iscloneable()) {
$arg = clone $arg;
$cast = is_a($arg, 'IteratorAggregate') ? iterator_to_array($arg) : get_object_vars($arg);
foreach ($cast as $key => $val) {
$arg->{$key} = $this->recursive($val, $func, array_merge($stack, array($arg)));
}
}
}
return $arg;
case 'array':
$copy = array();
foreach ($arg as $key => $val) {
$copy[$key] = $this->recursive($val, $func, array_merge($stack, array($arg)));
}
return $copy;
}
return $func($arg);
}
示例2: recursive
/**
* Invoke callback recursively for all data types
* @return mixed
* @param $arg mixed
* @param $func callback
* @param $stack array
**/
function recursive($arg, $func, $stack = NULL)
{
if ($stack) {
foreach ($stack as $node) {
if ($arg === $node) {
return $arg;
}
}
} else {
$stack = array();
}
switch (gettype($arg)) {
case 'object':
if (method_exists('ReflectionClass', 'iscloneable')) {
$ref = new ReflectionClass($arg);
if ($ref->iscloneable()) {
$arg = clone $arg;
foreach (get_object_vars($arg) as $key => $val) {
$arg->{$key} = $this->recursive($val, $func, array_merge($stack, array($arg)));
}
}
}
return $arg;
case 'array':
$tmp = array();
foreach ($arg as $key => $val) {
$tmp[$key] = $this->recursive($val, $func, array_merge($stack, array($arg)));
}
return $tmp;
}
return $func($arg);
}
示例3: dupe
/**
* Attempt to clone object
* @return object
* @return $arg object
**/
function dupe($arg)
{
if (method_exists('ReflectionClass', 'iscloneable')) {
$ref = new ReflectionClass($arg);
if ($ref->iscloneable()) {
$arg = clone $arg;
}
}
return $arg;
}
示例4: recursive
public function recursive($arg, $func, $stack = null)
{
if ($stack) {
foreach ($stack as $node) {
if ($arg === $node) {
return $arg;
}
}
} else {
$stack = [];
}
switch (gettype($arg)) {
case 'object':
if (method_exists('ReflectionClass', 'iscloneable')) {
$ref = new \ReflectionClass($arg);
if ($ref->iscloneable()) {
$arg = clone $arg;
$cast = is_a($arg, 'IteratorAggregate') ? iterator_to_array($arg) : get_object_vars($arg);
foreach ($cast as $key => $val) {
$arg->{$key} = $this->recursive($val, $func, array_merge($stack, [$arg]));
}
}
}
return $arg;
case 'array':
$copy = [];
foreach ($arg as $key => $val) {
$copy[$key] = $this->recursive($val, $func, array_merge($stack, [$arg]));
}
return $copy;
default:
throw new Exception("This method needs first argument to be an array or an object.");
}
return call_user_func_array($func, $arg);
}