Bug #71275 [NEW]: Bad method called on cloning an object having a trait

From: Date: Mon, 04 Jan 2016 16:09:16 +0000
Subject: Bug #71275 [NEW]: Bad method called on cloning an object having a trait
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198409@lists.php.net to get a copy of this message
From: patrick dot barroca at gmail dot com Operating system: Linux PHP version: 7.0.1 Package: Class/Object related Bug Type: Bug Bug description:Bad method called on cloning an object having a trait 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 bug report at https://bugs.php.net/bug.php?id=71275&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71275&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71275&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71275&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71275&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71275&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71275&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71275&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71275&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71275&r=support Expected behavior: https://bugs.php.net/fix.php?id=71275&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71275&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71275&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71275&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71275&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71275&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71275&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71275&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71275&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71275&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71275&r=mysqlcfg

« previous php.bugs (#198409) next »