Bug #60217 [Asn->Csd]: imposing requirements in traits
| From: | gron@php.net | Date: | Sat, 05 Nov 2011 01:48:31 +0000 |
| Subject: | Bug #60217 [Asn->Csd]: imposing requirements in traits | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-164902@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60217&edit=1
ID: 60217
Updated by: gron@php.net
Reported by: maus dot christian at googlemail dot com
Summary: imposing requirements in traits
-Status: Assigned
+Status: Closed
Type: Bug
Package: Class/Object related
Operating System: Ubuntu Linux 11.10
PHP Version: 5.4.0beta2
Assigned To: gron
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Fixed with SVN rev. 318793.
I also added the missing tests that ensure compatibility of abstract method
definitions.
Previous Comments:
------------------------------------------------------------------------
[2011-11-05 01:46:34] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&revision=318793
Log: Fixed Bug #60217 (Requiring the same method from different traits)
- also added test to check for inconsistent abstract method definitions, they need to be compatible
------------------------------------------------------------------------
[2011-11-04 13:12:06] maus dot christian at googlemail dot com
Description:
------------
Using multiple traits that depend on the same requirement using an abstract method fails with a
fatal error.
I tried using trait composition in order to move the requirement into a common trait, but this does
not work either.
Test script:
---------------
trait DoubleAmount {
public function doubleAmount() {
return $this->getAmount() * 2;
}
public abstract function getAmount();
}
trait TripleAmount {
public function tripleAmount() {
return $this->getAmount() * 3;
}
public abstract function getAmount();
}
class model {
use DoubleAmount, TripleAmount;
public function getAmount() {
return 23;
}
}
Actual result:
--------------
PHP Fatal error: Can't inherit abstract function TripleAmount::getAmount() (previously
declared abstract in DoubleAmount) in /home/maus/projects/traitstest/trait_abstract.php on line 30
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60217&edit=1