Bug #71275 [Opn->Asn]: Bad method called on cloning an object having a trait
| From: | bwoebi@php.net | Date: | Tue, 05 Jan 2016 14:00:09 +0000 |
| Subject: | Bug #71275 [Opn->Asn]: Bad method called on cloning an object having a trait | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198423@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71275&edit=1
ID: 71275
Updated by: bwoebi@php.net
Reported by: patrick dot barroca at gmail dot com
Summary: Bad method called on cloning an object having a
trait
-Status: Open
+Status: Assigned
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 7.0.1
-Assigned To:
+Assigned To: bwoebi
Block user comment: N
Private report: N
New Comment:
Yes, traits only, in case the method name matches any prefix of that length of a magic method...
Previous Comments:
------------------------------------------------------------------------
[2016-01-04 16:09:14] patrick dot barroca at gmail dot com
Description:
------------
I have a trait for translations that contains a public function _().
I clone an object that use this trait.
Expected : Object or trait method __clone() is called by PHP if present.
Actual : __clone() method is not called, _() method is called by PHP instead
This does not occur when the class itself have a _() method, this seems to be related to traits.
Test script:
---------------
<?php
trait MyTrait {
public function _() {
throw new RuntimeException('Should not be called');
}
}
class MyClass {
use MyTrait;
public function __clone() {
echo 'I\'m working hard to clone';
}
}
$instance = new MyClass();
clone $instance;
Expected result:
----------------
should display "I'm working hard to clone"
Actual result:
--------------
PHP Fatal error: Uncaught RuntimeException: Should not be called in [...]clone_poc.php:5
Stack trace:
#0 /home/pbarroca/workspace/clone_poc.php(20): MyClass->_()
#1 {main}
thrown in /home/pbarroca/workspace/clone_poc.php on line 5
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71275&edit=1