Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace DeepCopy; use ArrayObject; use DateInterval; use DateTimeInterface; use D..

Decoded Output download

<?php
 namespace DeepCopy; use ArrayObject; use DateInterval; use DateTimeInterface; use DateTimeZone; use DeepCopy\Exception\CloneException; use DeepCopy\Filter\ChainableFilter; use DeepCopy\Filter\Filter; use DeepCopy\Matcher\Matcher; use DeepCopy\Reflection\ReflectionHelper; use DeepCopy\TypeFilter\Date\DateIntervalFilter; use DeepCopy\TypeFilter\Spl\ArrayObjectFilter; use DeepCopy\TypeFilter\Spl\SplDoublyLinkedListFilter; use DeepCopy\TypeFilter\TypeFilter; use DeepCopy\TypeMatcher\TypeMatcher; use ReflectionObject; use ReflectionProperty; use SplDoublyLinkedList; class DeepCopy { private $hashMap = array(); private $filters = array(); private $typeFilters = array(); private $skipUncloneable = false; private $useCloneMethod; public function __construct($useCloneMethod = false) { $this->useCloneMethod = $useCloneMethod; $this->addTypeFilter(new ArrayObjectFilter($this), new TypeMatcher(ArrayObject::class)); $this->addTypeFilter(new DateIntervalFilter(), new TypeMatcher(DateInterval::class)); $this->addTypeFilter(new SplDoublyLinkedListFilter($this), new TypeMatcher(SplDoublyLinkedList::class)); } public function skipUncloneable($skipUncloneable = true) { $this->skipUncloneable = $skipUncloneable; return $this; } public function copy($object) { $this->hashMap = array(); return $this->recursiveCopy($object); } public function addFilter(Filter $filter, Matcher $matcher) { $this->filters[] = array("matcher" => $matcher, "filter" => $filter); } public function prependFilter(Filter $filter, Matcher $matcher) { array_unshift($this->filters, array("matcher" => $matcher, "filter" => $filter)); } public function addTypeFilter(TypeFilter $filter, TypeMatcher $matcher) { $this->typeFilters[] = array("matcher" => $matcher, "filter" => $filter); } private function recursiveCopy($var) { if ($filter = $this->getFirstMatchedTypeFilter($this->typeFilters, $var)) { return $filter->apply($var); } if (is_resource($var)) { return $var; } if (is_array($var)) { return $this->copyArray($var); } if (!is_object($var)) { return $var; } if (PHP_VERSION_ID >= 80100 && enum_exists(get_class($var))) { return $var; } return $this->copyObject($var); } private function copyArray(array $array) { foreach ($array as $key => $value) { $array[$key] = $this->recursiveCopy($value); } return $array; } private function copyObject($object) { $objectHash = spl_object_hash($object); if (isset($this->hashMap[$objectHash])) { return $this->hashMap[$objectHash]; } $reflectedObject = new ReflectionObject($object); $isCloneable = $reflectedObject->isCloneable(); if (false === $isCloneable) { if ($this->skipUncloneable) { $this->hashMap[$objectHash] = $object; return $object; } throw new CloneException(sprintf("The class "%s" is not cloneable.", $reflectedObject->getName())); } $newObject = clone $object; $this->hashMap[$objectHash] = $newObject; if ($this->useCloneMethod && $reflectedObject->hasMethod("__clone")) { return $newObject; } if ($newObject instanceof DateTimeInterface || $newObject instanceof DateTimeZone) { return $newObject; } foreach (ReflectionHelper::getProperties($reflectedObject) as $property) { $this->copyObjectProperty($newObject, $property); } return $newObject; } private function copyObjectProperty($object, ReflectionProperty $property) { if ($property->isStatic()) { return; } foreach ($this->filters as $item) { $matcher = $item["matcher"]; $filter = $item["filter"]; if ($matcher->matches($object, $property->getName())) { $filter->apply($object, $property->getName(), function ($object) { return $this->recursiveCopy($object); }); if ($filter instanceof ChainableFilter) { continue; } return; } } $property->setAccessible(true); if (method_exists($property, "isInitialized") && !$property->isInitialized($object)) { return; } $propertyValue = $property->getValue($object); $property->setValue($object, $this->recursiveCopy($propertyValue)); } private function getFirstMatchedTypeFilter(array $filterRecords, $var) { $matched = $this->first($filterRecords, function (array $record) use($var) { $matcher = $record["matcher"]; return $matcher->matches($var); }); return isset($matched) ? $matched["filter"] : null; } private function first(array $elements, callable $predicate) { foreach ($elements as $element) { if (call_user_func($predicate, $element)) { return $element; } } return null; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace DeepCopy; use ArrayObject; use DateInterval; use DateTimeInterface; use DateTimeZone; use DeepCopy\Exception\CloneException; use DeepCopy\Filter\ChainableFilter; use DeepCopy\Filter\Filter; use DeepCopy\Matcher\Matcher; use DeepCopy\Reflection\ReflectionHelper; use DeepCopy\TypeFilter\Date\DateIntervalFilter; use DeepCopy\TypeFilter\Spl\ArrayObjectFilter; use DeepCopy\TypeFilter\Spl\SplDoublyLinkedListFilter; use DeepCopy\TypeFilter\TypeFilter; use DeepCopy\TypeMatcher\TypeMatcher; use ReflectionObject; use ReflectionProperty; use SplDoublyLinkedList; class DeepCopy { private $hashMap = array(); private $filters = array(); private $typeFilters = array(); private $skipUncloneable = false; private $useCloneMethod; public function __construct($useCloneMethod = false) { $this->useCloneMethod = $useCloneMethod; $this->addTypeFilter(new ArrayObjectFilter($this), new TypeMatcher(ArrayObject::class)); $this->addTypeFilter(new DateIntervalFilter(), new TypeMatcher(DateInterval::class)); $this->addTypeFilter(new SplDoublyLinkedListFilter($this), new TypeMatcher(SplDoublyLinkedList::class)); } public function skipUncloneable($skipUncloneable = true) { $this->skipUncloneable = $skipUncloneable; return $this; } public function copy($object) { $this->hashMap = array(); return $this->recursiveCopy($object); } public function addFilter(Filter $filter, Matcher $matcher) { $this->filters[] = array("\x6d\x61\x74\143\150\145\x72" => $matcher, "\x66\x69\x6c\x74\x65\x72" => $filter); } public function prependFilter(Filter $filter, Matcher $matcher) { array_unshift($this->filters, array("\155\141\164\143\x68\x65\162" => $matcher, "\x66\x69\x6c\164\145\x72" => $filter)); } public function addTypeFilter(TypeFilter $filter, TypeMatcher $matcher) { $this->typeFilters[] = array("\155\x61\164\x63\x68\x65\162" => $matcher, "\x66\x69\154\164\145\162" => $filter); } private function recursiveCopy($var) { if ($filter = $this->getFirstMatchedTypeFilter($this->typeFilters, $var)) { return $filter->apply($var); } if (is_resource($var)) { return $var; } if (is_array($var)) { return $this->copyArray($var); } if (!is_object($var)) { return $var; } if (PHP_VERSION_ID >= 80100 && enum_exists(get_class($var))) { return $var; } return $this->copyObject($var); } private function copyArray(array $array) { foreach ($array as $key => $value) { $array[$key] = $this->recursiveCopy($value); } return $array; } private function copyObject($object) { $objectHash = spl_object_hash($object); if (isset($this->hashMap[$objectHash])) { return $this->hashMap[$objectHash]; } $reflectedObject = new ReflectionObject($object); $isCloneable = $reflectedObject->isCloneable(); if (false === $isCloneable) { if ($this->skipUncloneable) { $this->hashMap[$objectHash] = $object; return $object; } throw new CloneException(sprintf("\x54\x68\x65\40\143\154\x61\163\x73\x20\x22\x25\163\42\40\x69\x73\40\156\x6f\164\x20\x63\x6c\x6f\x6e\x65\141\142\154\x65\56", $reflectedObject->getName())); } $newObject = clone $object; $this->hashMap[$objectHash] = $newObject; if ($this->useCloneMethod && $reflectedObject->hasMethod("\137\137\143\x6c\157\156\x65")) { return $newObject; } if ($newObject instanceof DateTimeInterface || $newObject instanceof DateTimeZone) { return $newObject; } foreach (ReflectionHelper::getProperties($reflectedObject) as $property) { $this->copyObjectProperty($newObject, $property); } return $newObject; } private function copyObjectProperty($object, ReflectionProperty $property) { if ($property->isStatic()) { return; } foreach ($this->filters as $item) { $matcher = $item["\x6d\141\164\x63\150\x65\x72"]; $filter = $item["\146\151\154\x74\145\x72"]; if ($matcher->matches($object, $property->getName())) { $filter->apply($object, $property->getName(), function ($object) { return $this->recursiveCopy($object); }); if ($filter instanceof ChainableFilter) { continue; } return; } } $property->setAccessible(true); if (method_exists($property, "\x69\x73\111\x6e\x69\x74\x69\141\154\x69\172\x65\144") && !$property->isInitialized($object)) { return; } $propertyValue = $property->getValue($object); $property->setValue($object, $this->recursiveCopy($propertyValue)); } private function getFirstMatchedTypeFilter(array $filterRecords, $var) { $matched = $this->first($filterRecords, function (array $record) use($var) { $matcher = $record["\155\141\164\143\150\145\x72"]; return $matcher->matches($var); }); return isset($matched) ? $matched["\x66\151\x6c\x74\x65\162"] : null; } private function first(array $elements, callable $predicate) { foreach ($elements as $element) { if (call_user_func($predicate, $element)) { return $element; } } return null; } }

Function Calls

None

Variables

None

Stats

MD5 7f6371ce0579407426f22e869325c9d0
Eval Count 0
Decode Time 95 ms