当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionClass::iscloneable方法代码示例

本文整理汇总了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);
 }
开发者ID:Podbe,项目名称:Podbe_V4-firtz-node,代码行数:40,代码来源:base.php

示例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);
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:39,代码来源:base.php

示例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;
 }
开发者ID:adamjdev,项目名称:opps,代码行数:15,代码来源:base.php

示例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);
 }
开发者ID:schpill,项目名称:standalone,代码行数:35,代码来源:utils.php


注:本文中的ReflectionClass::iscloneable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。