php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59526 Imagick::clone() method prevents creating mock objects
Submitted: 2010-12-02 15:08 UTC Modified: 2010-12-02 15:22 UTC
From: nickp at smartertravelmedia dot com Assigned:
Status: Closed Package: imagick (PECL)
PHP Version: 5.2.5 OS: CentOS 5.3
Private report: No CVE-ID: None
 [2010-12-02 15:08 UTC] nickp at smartertravelmedia dot com
Description:
------------
Because the Imagick class has a method named 'clone' a mock object for it cannot be created. Having the string 'clone' as the name of a method causes a syntax error since 'clone' is a PHP keyword.

I believe the solution is to rename the method to something like 'copy' since that is not a reserved PHP keyword.

I'm running version 2.3.0 of the imagick package but I believe this would affect all versions since the documentation indicates there is still a method named 'clone' in the most recent release.

Reproduce code:
---------------
<?php

require_once 'PHPUnit/Framework/TestCase.php';

class MyTestCase extends PHPUnit_Framework_TestCase {

    public function testSomething() {
        $img = $this->getMock('Imagick');
    }
}

$test = new MyTestCase();
$test->testSomething();


Expected result:
----------------
[blank]

Actual result:
--------------
PHP Parse error:  syntax error, unexpected T_CLONE, expecting T_STRING in /var/www/{release path}/PHPUnit/Framework/MockObject/Mock.php(228) : eval()'d code on line 207

Parse error: syntax error, unexpected T_CLONE, expecting T_STRING in /var/www/{release path}/PHPUnit/Framework/MockObject/Mock.php(228) : eval()'d code on line 207
PHP Fatal error:  Class 'Mock_Imagick_ab833f80' not found in /var/www/{release path}/PHPUnit/Framework/TestCase.php on line 672

Fatal error: Class 'Mock_Imagick_ab833f80' not found in /var/www/{release path}/PHPUnit/Framework/TestCase.php on line 672


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-02 15:19 UTC] mkoppanen@php.net
Hi,

I will deprecate the method but cannot remove/rename before next major version, as it might break existing code.
 [2010-12-02 15:21 UTC] nickp at smartertravelmedia dot com
Sounds good. Thank you.
 [2010-12-02 15:22 UTC] mkoppanen@php.net
This bug has been fixed in SVN.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

Deprecated in subversion.
 [2010-12-02 22:57 UTC] paulgao at yeah dot net
what is new method name?
 [2011-05-23 18:19 UTC] kris dot johansen at blackpepper dot co dot nz
use the clone keyword 
http://php.net/manual/en/language.oop5.cloning.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 17:01:31 2024 UTC