We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The current NodeInterface::clone() method uses unserialize() and serialize().
This is not the best solution to clone an object, ideally we should have used __clone().
__clone()
I've tests many solutions and the only one that works is with unserialize(serialize()).
unserialize(serialize())
You can easily test your solution using this code:
<?php declare(strict_types = 1); use Graphp\GraphViz\GraphViz; include './vendor/autoload.php'; $exporterGraph = new \drupol\phptree\Exporter\Graph(); $root = new \drupol\phptree\Node\ValueNode('root', 2); $root[] = new \drupol\phptree\Node\ValueNode('foo'); $clone = $root->clone(); echo 'Root count: ' . iterator_count($root->all()) . "\n"; echo 'Second clone count: ' . iterator_count($clone->all()) . "\n"; var_dump($root === $root[0]->getParent()); var_dump(sha1(spl_object_hash($root)) . ' === ' . sha1(spl_object_hash($root[0]->getParent()))); (new GraphViz())->setFormat('svg')->display($exporterGraph->export($root)); var_dump($clone === $clone[0]->getParent()); var_dump(sha1(spl_object_hash($clone)) . ' === ' .sha1(spl_object_hash($clone[0]->getParent()))); (new GraphViz())->setFormat('svg')->display($exporterGraph->export($clone));
The text was updated successfully, but these errors were encountered:
Issue #6: Replace unserialize() and serialize() with proper clone calls.
fbe7e0f
7be956b
Fixed.
Sorry, something went wrong.
No branches or pull requests
The current NodeInterface::clone() method uses unserialize() and serialize().
This is not the best solution to clone an object, ideally we should have used
__clone()
.I've tests many solutions and the only one that works is with
unserialize(serialize())
.You can easily test your solution using this code:
The text was updated successfully, but these errors were encountered: