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

Avoid cloning uncloneables #8

Merged

Conversation

davedevelopment
Copy link
Contributor

Fixes #7

I used XMLReader as I'm pretty sure that's everywhere theses days, and it doesn't have a __clone method.

The bug @whatthejeff mentioned (https://bugs.php.net/bug.php?id=53967) might bring further weirdness at some point, SplFileObject seems happy to be cloned if it's been instantiated using instantiator, but not if it's a "proper" instance?

PHP 5.6.0 (cli) (built: Oct  4 2014 20:41:37)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
<?php

require "vendor/autoload.php";

$instantiator = new \Doctrine\Instantiator\Instantiator();
$instance = $instantiator->instantiate('SplFileObject');

$b = clone $instance;

$a = new SplFileObject(__FILE__);
$b = clone $a;
PHP Fatal error:  main(): An object of class SplFileObject cannot be cloned in /Users/davem/src/instantiator/test.php on line 11
PHP Stack trace:
PHP   1. {main}() /Users/davem/src/instantiator/test.php:0

shell returned 255

@davedevelopment
Copy link
Contributor Author

Oh, isCloneable is (PHP >= 5.4.0), that's annoying...

@Ocramius
Copy link
Member

Ocramius commented Oct 4, 2014

Oh, isCloneable is (PHP >= 5.4.0), that's annoying...

method_exists :-(

@Ocramius Ocramius self-assigned this Oct 4, 2014
@Ocramius Ocramius added this to the 1.0.3 milestone Oct 4, 2014
@Ocramius Ocramius added the bug label Oct 4, 2014
Ocramius added a commit that referenced this pull request Oct 4, 2014
@Ocramius Ocramius merged commit 0b59c15 into doctrine:master Oct 4, 2014
@Ocramius
Copy link
Member

Ocramius commented Oct 4, 2014

@davedevelopment merged, tagged 1.0.3, thanks!

Ocramius added a commit to Ocramius/Instantiator that referenced this pull request Oct 4, 2014
Ocramius added a commit to Ocramius/Instantiator that referenced this pull request Oct 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instantiator attempts to clone classes that are not cloneable
2 participants