Skip to content
New issue

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

Adds support of internal child class instantiation #61

Merged
merged 3 commits into from
Oct 21, 2019
Merged

Adds support of internal child class instantiation #61

merged 3 commits into from
Oct 21, 2019

Conversation

gquemener
Copy link
Contributor

Related to #39

This is my attempt to resolve a long on-going issue on the phpspec repository, taking inspiration on the SF VarExporter component.

I do not see any other missing testcases, however feel free to let me know if you think about some, I will happily add them.

/cc @ciaranmcnulty @Ocramius @mikeSimonson

@Ocramius Ocramius added this to the 1.3.0 milestone Oct 21, 2019
@gquemener
Copy link
Contributor Author

Wait, don't merge yet, there's something odd going on

@gquemener
Copy link
Contributor Author

Allright, that's better now. Cloning ArrayIterator results in the original array being referenced in cloned objects, which will probably lead to unwanted side effects.

Here's an example:

<?php

require __DIR__ . '/vendor/autoload.php';

final class MyIterator extends \ArrayIterator
{
}

$instantiator = new \Doctrine\Instantiator\Instantiator();
$o1 = $instantiator->instantiate(\MyIterator::class);
$o2 = $instantiator->instantiate(\MyIterator::class);
$o3 = $instantiator->instantiate(\MyIterator::class);
$o3->append('foo');
die(var_dump($o1, $o2, $o3));

Which outputs:

/app/try.php:14:
class MyIterator#2 (1) {
  private $storage =>
  array(1) {
    [0] =>
    string(3) "foo"
  }
}
/app/try.php:14:
class MyIterator#7 (1) {
  private $storage =>
  class MyIterator#6 (1) {
    private $storage =>
    class MyIterator#2 (1) {
      private $storage =>
      array(1) {
        [0] =>
        string(3) "foo"
      }
    }
  }
}
/app/try.php:14:
class MyIterator#8 (1) {
  private $storage =>
  class MyIterator#6 (1) {
    private $storage =>
    class MyIterator#2 (1) {
      private $storage =>
      array(1) {
        [0] =>
        string(3) "foo"
      }
    }
  }
}

@gquemener
Copy link
Contributor Author

Let me know if you'd rather have one commit in this PR.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Ocramius Ocramius self-assigned this Oct 21, 2019
@Ocramius Ocramius merged commit ae466f7 into doctrine:master Oct 21, 2019
@Ocramius
Copy link
Member

Thanks @gquemener!

@gquemener gquemener deleted the final-serializable-internal-child-fix branch October 21, 2019 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants