myclabs / myclabs/DeepCopy

Does not properly clone classes inherited from ArrayObject

Open
#152 0 comments 0 reactions 1 assignee View on GitHub

@theofidry is already working on this.

Since Mar 19, 2020.

bug
Dominant language
PHP
Stars
8.9k
Forks
110
PR merge metrics
No merged PRs in 30d

Description

When cloning an object of an ArrayObject-inherited class, deep_copy returns ArrayObject object instead of the actual clone of the supplied object. Obviously, all custom properties are lost in the process.

Example:

class TheTest extends ArrayObject {
    public $x = 1;
}

$a = new TheTest();
$b = DeepCopy\deep_copy($a);

echo 'get_class($a) = ', get_class($a), "\n";
echo '$a->x = ', $a->x ?? "<none>", "\n\n";

echo 'get_class($b) = ', get_class($b), "\n";
echo '$b->x = ', $b->x ?? "<none>", "\n";

Output:

get_class($a) = TheTest
$a->x = 1

get_class($b) = ArrayObject
$b->x = <none>

$b should be a carbon copy of $a, but it's not.

DeepCopy version: 1.9.5.

PHP version:

PHP 7.3.11-0ubuntu0.19.10.3 (cli) (built: Feb 12 2020 15:22:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.11-0ubuntu0.19.10.3, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.