myclabs / deepcopy Goto Github PK
View Code? Open in Web Editor NEWCreate deep copies (clones) of your objects
License: MIT License
Create deep copies (clones) of your objects
License: MIT License
I suggest PHPStan.
Hello,
I have a Symfony2 project with Doctrine2 and I try to use DroctrineEmptyCollectionFilter so as to reset a array collection property while the deepCopy but it does not seem to work. The property keeps his array with all the data from the copied object :
$styleProperty = $em
->getRepository('MyAppMainBundle:StyleProperty')
->findOneById(9);
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
$deepCopy->addFilter(
new DoctrineEmptyCollectionFilter(), new PropertyMatcher('MyApp\MainBundle\Entity\StyleProperty','stylePropertyByStyleElement'));
$newStyleProperty = $deepCopy->copy($styleProperty);
Do I do something wrong?
As @IMM0rtalis mentioned it in his comment #18 (comment) there is in my opinion an undesired behavior with following code:
$copyHelper = new DeepCopy();
$copyHelper->addFilter(new DoctrineProxyFilter(), new DoctrineProxyMatcher());
$copyHelper->addFilter(new SetNullFilter(), new PropertyNameMatcher('id'));
The DeepCopy-Class loads the proxy, but do not apply further filters like to set null the id. Therefore, Doctrine can not handle the copied entity as a new entity.
Do I see it correclty?
Best,
Christoph
Since I updated to PHP 7.0.7 I have an issue duplicating objects with a DateTime property. Every version before 7.0.7 worked without any issues.
the error I am getting is;
Notice: Undefined property: DateTime::$date
The error is thrown at this line:
$propertyValue = $property->getValue($object);
DeepCopy/src/DeepCopy/DeepCopy.php
Line 179 in a877399
there are older bug reports from PHP regarding this issue, so I am unsure if this library should be improved or that this is just PHP related;
http://stackoverflow.com/questions/14084222/why-cant-i-access-datetime-date-in-phps-datetime-class-is-it-a-bug
Also see my try on 3v4l to isolate the issue;
https://3v4l.org/NOGDr
I have one doubt lets said that I've entities A, B and C, A hasMany B and B hasMany C but C can have many B also, how should my code looks like? Also I want to clone A but keeping the same information in cloned B and C meaning the only I want to update is the reference to the cloned A, is that what DeepClone does? Any advice? Could you provide an answer explaining this?
When I save an deepcloned entity, the entity is saved double.
A code snippet
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
$copy = $deepCopy->copy($item);
//Frefresh the old item
$em->refresh($item);
//Detach the clone
$em->detach($copy);
//Persist the clone
$em->persist($copy);
$em->flush();
Hey guys, I am facing a bit of dilemma here. The situation is as follows:
I am currently trying to clone a rather complex tree of documents that I retrieved via doctrine from MongoDB. In order to persist the newly clones documents again, I need to either strip them of their ids or replace new them with new ids (\MongoId to be precise).
My initial approach therefore was to either use replace filter or a setNullFilter like this:
$deepCopy->addFilter(new SetNullFilter(), new PropertyNameMatcher('id'));
But then I ran into the exception that DeepCopy still encountered some MongoId Objects that are uncloneable (Which is how I stumbled over the bug I fixed the other day). As it turns out, MongoId Objects are also used in properties that are not called 'id'. Still I thought the fix was rather easy:
$deepCopy->addFilter(new SetNullFilter(), new PropertyTypeMatcher('MongoId'));
After all, this approach should handle all Objects of the MongoId kind, right ? In fact, it does but not in the way I intended it to. It turns out, we use MongoId Objects to reference other objects. These references however should be kept during copying and not be nulled.
Still, I thought the fix was rather easy. I just write my own filter that either duplicates the id manually or keeps it, depending on the property name:
use DeepCopy\Filter\Filter;
class MongoIdFilter implements Filter
{
/**
* {@inheritdoc}
*/
public function apply($object, $property, $objectCopier)
{
$reflectionProperty = new \ReflectionProperty($object, $property);
$reflectionProperty->setAccessible(true);
if ($property === 'id') {
$value = new \MongoId();
} else {
ldd($reflectionProperty->getValue($object));
$value = new \MongoId((string) $reflectionProperty->getValue($object));
}
$reflectionProperty->setValue($object, $value);
}
}
Yet, I still run into the exception:
[DeepCopy\Exception\CloneException]
Class "MongoId" is not clone able.
Via debugging I found out that my filter is being executed, but apparently not in every case. I seem to be missing something. Is there any other, preferred way, I should handle this situation ?
Best regards
Jan
Last time I looked, I couldn't find any way to really squeeze much more perf. This is mainly due to the fact that DeepCopy
deep copy an object. As such, you cannot assume the properties of that object as values can be dynamically added. The result is DeepCopy
must rely on a brand new instance of ReflectionObject
each time, even if you get two objects of the same class.
A way to change that would maybe to add a mode to clone class instances instead, i.e. to rely on ReflectionClass
and cache it somehow.
But to be honest this is just an idea like that. I'm actually not sure if it's really worth it, maybe it would be better to start by having a benchmark and see if the perf gain is worth it.
I believe this is due to the way it iterates over properties using ReflectionObject::getProperties().
Is this expected, or undefined behaviour? I can't decide :\
Hi,
i'm getting this error when i follow README instructions for installing.
Class "ReflectionClass" is not cloneable.
This is my code (my "duplicate" controller):
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository("AppBundle:MyEntity")->find($id);
$deepCopy = new DeepCopy();
$clone = $deepCopy->copy($entity);
$clone->setName("Copy of " . $clone->getName());
$em->persist($clone);
$em->flush();
Thanks!
Since we upgraded to the latest version, 1.4.0 we are getting this error when running tests in codeception.
PDOException: SQLSTATE[HY000]: General error: property queryString is read only
#1 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:160
#2 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:123
#3 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:75
#4 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:160
#5 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:123
#6 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:75
#7 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:86
#8 DeepCopy\DeepCopy->DeepCopy\{closure}
#9 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:89
#10 /var/jenkins/workspace/Integration-API-MAIN-PHP-Testing/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:68
If you have an entity like this:
class thing {
/** @var ArrayCollection **/
private $blas;
public function setBlas($blas) {
// setting logic
}
public function addBla($bla) {
// adding logic
}
public function removeBla($bla) {
// removing logic
}
}
If you implement the DoctrineCollectionFilter to copy the vales stored in $this->blas
, the code uses Symfony's PropertyAccessor class that prioritises the use of remove/add over set. Thus it will attempt to alter the contents of the ArrayCollection, but the ArrayCollection itself will be the reference to the original one, and not a copy. If you remove the removeBla()
method from the example above, it will use setBlas
that can be used to create a new ArrayCollection and therefore not use the reference to the original.
Simply try to DeepCopy $GLOBALS. It crashes with stack overflow.
Add a mode where dynamic properties can be skipped: I expect this could significantly improve performances and be good enough for some users.
Hi, in my example I need to have access to the "source" object because I'd like to link it in one of the cloned properties.
class Foo
{
/** @var Foo */
protected $source;
}
// A DeepCopy\Filter\Filter would do this.
$cloner = new DeepCopy();
$foo = new Foo();
$result = $cloner->copy($foo);
// $result->source == $foo;
The DeepCopy\Filter\Filter::apply($object, $property, $objectCopier)
interface should allow the "source" object, therefore DeepCopy::copyObjectProperty
aswell.
My first idea was to extend DeepCopy and override some methods, but is too private. I know this feature is not a "cloning" thing but it could be interesting. Is there other way to accomplish??
Thanks!
Specifically, Class "MongoDB\BSON\ObjectID" is not cloneable.
This is a trivial object that simply contains a 24 character hex string. Cloning it is trivial:
$orig = new ObjectID;
$clone = new ObjectID((string) $orig);
I suspect there may be issues with the other BSON types as well, but there's no reason these shouldn't be easily cloneable. It might make more sense to wait for Mongo to get their act together and fix their extension, though.
In several issues i read a lot of nice ideas how to improve this nice project. But like already suggested from others I would like to have a branch 2.0 or sth like this. Can you create this pls?
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating optimized autoload files
Illuminate\Foundation\ComposerScripts::postUpdate
PHP Warning: Uncaught ErrorException: require(C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer/../myclabs/deep-copy/src/DeepCopy/deep_copy.php): failed to open stream: No such file or directory in C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php:66
Stack trace:
#0 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php(66): Composer\Util\ErrorHandler::handle(2, 'require(C:\User...', 'C:\Users\Gary-C...', 66, Array)
#1 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php(66): require()
#2 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php(56): composerRequirec1eacf11190380a1fd3b9f0e78877bfb('6124b4c8570aa39...', 'C:\Users\Gary-C...')
#3 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\autoload.php(7): ComposerAutoloaderInitc1eacf11190380a1fd3b9f0e78877bfb::getLoader()
#4 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\laravel\framework\src in C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php on line 66
Warning: Uncaught ErrorException: require(C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer/../myclabs/deep-copy/src/DeepCopy/deep_copy.php): failed to open stream: No such file or directory in C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php:66
Stack trace:
#0 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php(66): Composer\Util\ErrorHandler::handle(2, 'require(C:\User...', 'C:\Users\Gary-C...', 66, Array)
#1 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php(66): require()
#2 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php(56): composerRequirec1eacf11190380a1fd3b9f0e78877bfb('6124b4c8570aa39...', 'C:\Users\Gary-C...')
#3 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\autoload.php(7): ComposerAutoloaderInitc1eacf11190380a1fd3b9f0e78877bfb::getLoader()
#4 C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\laravel\framework\src in C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php on line 66
PHP Fatal error: composerRequirec1eacf11190380a1fd3b9f0e78877bfb(): Failed opening required 'C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer/../myclabs/deep-copy/src/DeepCopy/deep_copy.php' (include_path='C:\xampp\php\PEAR') in C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php on line 66
Fatal error: composerRequirec1eacf11190380a1fd3b9f0e78877bfb(): Failed opening required 'C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer/../myclabs/deep-copy/src/DeepCopy/deep_copy.php' (include_path='C:\xampp\php\PEAR') in C:\Users\Gary-Carvajal\Documents\GitHub\blsempl_unah\vendor\composer\autoload_real.php on line 66
When updating the composer gives me this error if someone has the solution please could you help me......
Like return types for Matcher and Filter
Hello all,
i'm trying to use your bundle using doctine in Symfony2.
I try to clone an entity named StyleProperty witch has 2 one2many relations and i want it to clone only in one way (styleProperty and all his StyleValues) so I use an KeepFilter not to clone StylePropertyByStyleElement.
$styleProperty = $em
->getRepository('MyAppMainBundle:StyleProperty')
->findOneById(9);
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
$deepCopy->addFilter(new KeepFilter(), new PropertyMatcher('MyApp\MainBundle\Entity\StyleProperty','stylePropertyByStyleElement'));
$newStyleProperty = $deepCopy->copy($styleProperty);
$em->persist($newStyleProperty);
$em->flush();
I also tried to set as emptyCollecion :
$deepCopy->addFilter(
new DoctrineEmptyCollectionFilter(), new PropertyMatcher('MyApp\MainBundle\Entity\StyleProperty','stylePropertyByStyleElement'));
But it did not work too. :s
It should clone StyleProperty and StyleValue (witch only has an idStyleProperty) but it always wants to clone $stylePropertyByStyleElement and duplicate everything and continue to clone with stylePropertyByStyleElement childs ...
What do I do wrong?
Thank you a lot.
Hello,
There is some fix on master :
1.5.0...master
especially this one : #29
Can you bump version please in order to avoid rely on dev-master please ?
thanks
Doing the following still tries to copy the User object - how do I stop this cloning happening?
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new SetNullFilter(), new PropertyNameMatcher('user_id'));
$deepCopy->addFilter(new SetNullFilter(), new PropertyNameMatcher('user'));
$clone = $deepCopy->copy($entity);
Right now an matcher gets a string as a second argument, cf. this line. IMO this is quite inefficient for two reasons:
ReflectionProperty
is much more powerful and easy to manipulate than just a name. For example in PropertyTypeMatcher we end up doing reflection again... when it could be just passed down.ReflectionProperty
, you actually get the right one.Besides documenting it, I would even recommend it. IMO the biggest selling point of DeepCopy is it's ease of use even on array structures. I don't really like the OOP usage of it and prefer to put it in a function instead like in alice: https://github.com/nelmio/alice/blob/master/src/functions.php#L12
However that's it: I use it because it's convenient. The other selling point of the library is handling cycling graph, but 9/10 a cycling graph is due to a mistake somewhere. Not that there isn't legitimate use cases, but they are very rare.
Is there a reason not to have a factory to always return the same instance of DeepCopy
? Creating a new instance each time comes with an overhead and prevent any use of the internal cashing as nothing is static. For this profile, you can see that it can get quite bad. To be taken with a grain of salt as in the benchmark I was creating a new instance of DeepCopy which has a certain overhead for sure, but from the profiling you can see that most of the time lost comes from the cashing.
For now, filter applies only on property of an object. But for filter PropertyByTypeFilter
, it would be more consistent, if its applies on all existing instances of specified type that appears inside copied elemnt, so not just object properties, but also members of arrays, or copied object itself (i.e. $deepCopy->clone(\Mockery::mock(MySuperClass::class)
).
This is particullary useful to configure DeepCopy to skip all mocked instances (I'm using Mockery), which oviously, DeepCopy fails to clone.
I have a parent entity named "Sitios" that haves 3 OneToMany associations: "Archivos", "Paginas" and "Hostings"... I am trying to clone the site including the files and pages, and resetting hostings to an empty collection and a "desarrollador" property that needs to be set to null.
this is my code:
$q = $this->entityManager
->createQuery('SELECT s,pg,fl FROM IDP:Sitios s
JOIN s.paginas pg
JOIN s.archivos fl
WHERE s.idSitio = :sid')
->setParameter('sid', $sid);
$s = $q->getSingleResult();
if ($s == null) {
throw new EXP\NotFound('invalid_site');
}
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new SetNullFilter(), new PropertyMatcher('Domain\Sitios', 'desarrollador'));
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyMatcher('Domain\Sitios', 'paginas'));
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyMatcher('Domain\Sitios', 'archivos'));
$deepCopy->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyMatcher('Domain\Sitios', 'hostings'));
$sCopy = $deepCopy->copy($s);
$this->entityManager->persist($sCopy);
try {
$this->entityManager->flush();
} catch (\Exception $e) {
throw new EXP\InternalError($e->getMessage());
}
But only the Sitio class gets cloned and all the references remains to the original Paginas and Files objects... the desarrollador attribute is not set to null and hostings is alredy empty, so I cant tell if it is working or not...
I have also tried with the collections example
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
but had no luck... can anyone give me a hand please?
I'm trying to make a copy from a Symfony command.
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new DoctrineProxyFilter(), new DoctrineProxyMatcher());
$deepCopy->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
$myCopy = $deepCopy->copy($product);
But, I got this error:
The identifier id is missing for a query of AppBundle\Entity\Category
It's trying to load the associated entities, but for some reasons the it cannot make the query.
But if I execute the above code from a controller action, it works.
Am I forgetting something?
I've got this error while do phpunit.. PHP Fatal error: Cannot redeclare DeepCopy\deep_copy() (previously declared in /usr/share/php/DeepCopy/deep_copy.php:13)
Maybe add check function_exists before declare function should be a solution.
I know your project is used more braodly. But I am using Doctrine 2 and trying to copy entites, which are now generated, but cannot be written to the database because they are not persistet. I can and will not set cascading persists in our project, so I was wondering if I can use the filter mechanism to persist entities upon creation?
Hey, ๐
I am packaging DeepCopy on gentoo, to have a complete phpunit, source-only, in our tree,
I noticed that the tests are not in the tarball, maybe I missed something,
I have packaged composer (and all dependencies) and it is not so common for upstreams,
to have tests only in the git tree.
Is there a way that the tests can be in the tarball in the next release ?
Problem: KeepFilter
is only implemented as a regular filter, so to apply it by type one must use the deprecated PropertyTypeMatcher
. Ergo PropertyTypeMatcher
should not be deprecated until all the regular filters are implemented as type filters.
That is, it's a bad idea to deprecate something without providing an alternative.
We should create copy of entity with cnahging it class (doctrine single table inheritance). Currently library doesn't support this.
I'd like to start off by saying I am very surprised a basic inheritance issue such as this still exists in software that has been in development for four years.
As demonstrated in the following example, the filter's matcher (i.e. PropertyTypeMatcher
) is expected to access a private property of the parent class in a derived class. Needless to say, it fails, because the property does not exist in the derived class.
class A {
private $foo;
public function __construct($foo) {
$this->foo = $foo;
}
}
class B extends A {}
$copier = new DeepCopy;
$copier->addFilter(new KeepFilter, new PropertyTypeMatcher(stdClass::class));
$copier->copy(new B((object)[]);
Property B::$foo does not exist
src\DeepCopy\Matcher\PropertyTypeMatcher.php:33
I'm not really sure what's the interest of having an addFilter
and co. when everything could be added in the constructor.
Hi, i need some argumentation help here:
What is the benefit of DeepCopy against the deserialize-serialize hack proposed here:
http://php.net/manual/de/language.oop5.cloning.php#87066
Except the Filters and Matchers of course.
It is currently possible to use the KeepFilter
with the PropertyTypeMatcher
(no exception thrown) but it's not working:
$deepCopy = new DeepCopy();
...
$deepCopy->addFilter(new KeepFilter(), new PropertyTypeMatcher('AppBundle\Entity\Group'));
...
$versionCopy = $deepCopy->skipUncloneable()->copy($version);
I have this error:
Doctrine\ORM\ORMInvalidArgumentException: A new entity was found through the relationship 'AppBundle\Entity\Version#groups' that was not configured to cascade persist operations for entity: AppBundle\Entity\Group@000000003121925c000000001779ad23. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'AppBundle\Entity\Group#__toString()' to get a clue.
The filters
property is iterate after cloning the object (https://github.com/myclabs/DeepCopy/blob/master/src/DeepCopy/DeepCopy.php#L137), but should be checked before the clone (https://github.com/myclabs/DeepCopy/blob/master/src/DeepCopy/DeepCopy.php#L119).
If the relation is fully hydrated (ie, no proxy) everything is good, and my "id" property matcher can set the property to null.
If, however, the relation isn't retrieved in the query, the related object is Proxy instance, and DeepCopy won't set the ID of that object to null.
Has anyone had this problem, and has anyone got a workaround, other than hydrating everything before copying (which might be the most sensible thing to do anyway)?
DoctrineEmptyCollectionFilter does not appear to be used in this repo, but it is there and also references "Doctrine\Common\Collections\ArrayCollection" which is not included.
Similarly, the class "Proxy" (Doctrine\Common\Persistence\Proxy) also does not exist is referenced by DoctrineProxyMatcher.
This does not affect the project's runtime, but I found this result through a kind of static analysis tool.
Hi
Any chance of a new release please? A couple of fixes have made their way in now which I'm reliant on and I'd prefer not to be running from dev-master if at all possible!
Thanks!
Hi.
next lines in code are buggy, that our project failing today:
$objectHash = spl_object_hash($object);
..........
..........
$newObject = clone $object;
//One of two situations (I do not know correct solution)
//1)
$this->hashMap[spl_object_hash($newObject)] = $newObject; //<--- BUG: need use spl_object_hash($newObject) instead previous $objectHash
//2)
$this->hashMap[$objectHash] = $object;//<---- store old object
What is happening: The current $object will free (as cloned from previous recursions). The php reusing this $objectHash for new cloned $object. But in this case, the copy process returning old not correct $object from $this->hashMap.
PLEASE fix it and inform me (I don't want to inject my codes inside ).
Hi
I have two entities with a BIDirectional Relationship, Timeslices and Activities.
Timeslice has an Ativity and Activity has multiple Timeslices.
When i Copy a Timeslice i want to keep the Reference to Activity. I Use a KeepFilter for that which Keeps the Activity but does not update the Timeslices Field in Activity. Doctrine thus looses the Relationship.
If I remove the KeepFilter It tries to make a new Activity which isnt desired either.
Have you encountered this Situation before?
A fair amount of those classes, to not say all, should be final. While it's not doable in 1.x, maybe we could mark them as @final
already.
Hi,
I've updated to 1.4.0 and my tests failed with a Maximum function nesting level of '200' reached, aborting exception.
Rolled back to 1.3.1 everything went back to normal.
I don't know if I missed something (config or ... something) but I thought you might be notified.
thanks
For version 2.0
of this package, could we support PHP 7
and use PHPUnit 6
?
the same code is working with php-fpm and fails on hhvm.
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new DoctrineCollectionFilter(), new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
$deepCopy->copy($object);
Uncaught PHP Exception BadMethodCallException: "Trying to clone an uncloneable object of class ReflectionClass" at line {"exception":"[object](BadMethodCallException%28code: 0%29: Trying to clone an uncloneable object of class ReflectionClass at :)
hhvm --version
HipHop VM 3.5.0-dev (rel)
Compiler: heads/master-0-gcb697d9b910189e25fbddce39e7672dfd27d4f04
Repo schema: 8b97230efbcbe284b1e86ce2768b04e5145b36f2
Extension API: 20140829
Here are some examples:
$obj = new stdClass();
$obj->foo = $foo;
or more complex:
$foo = new stdClass();
$bar = new stdClass();
$foo->bar = $bar;
$bar->foo = $foo;
Are these cases supported?
Hi.
Great lib, seems to do just what I need.
Trying it for the first time, and having some trouble.
I have a survey entity fetched from db:
$surveyEntity = $em->getRepository('AppSurveyBundle:Survey')->findOneBy(array('id' => $surveyId, 'deleted' => null));
This is the entity I want to clone, so;
$deepCopy = new DeepCopy();
$deepCopy->addFilter(new SetNullFilter(), new PropertyNameMatcher('id'));
$newSurveyEntity = $deepCopy->copy($surveyEntity);
Trying to run this, I get an exception telling me that "'App\UserBundle\Entity\User' is not cloneable.".
This entity is not referenced anywhere in my entity as far as I can tell. Searched through the entire bundle for any signs of "user", but there are none, as expected. My user entity has nothing to do with the survey entity.
Any pointers for me debugging this?
What makes an entity un-clonable?
More an idea than a feature request. In some of my applications I often end up with something like that:
if (false === function_exists('deep_clone')) {
/**
* Deep clone the given value.
*
* @param mixed $value
*
* @return mixed
*/
function deep_clone($value)
{
return (new \DeepCopy\DeepCopy())->copy($value);
}
}
e.g. in the wild: alice (it's not the only one).
Which actually could be enhanced by being put in a namespace like done in nikic/iter:
namespace MyNamespace;
/**
* Deep clone the given value.
*
* @param mixed $value
*
* @return mixed
*/
function deep_clone($value)
{
return (new \DeepCopy\DeepCopy())->copy($value);
}
}
I think it could be a nice to have as makes it easier to use (provided you don't have custom config to do).
Notice: Undefined property: DateInterval::$have_weekday_relative
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.