|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67097 Allow traits to require class/interface
Submitted: 2014-04-18 21:17 UTC Modified: 2017-09-10 21:10 UTC
Avg. Score:3.8 ± 1.6
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: thierry at byscripts dot info Assigned:
Status: Suspended Package: Class/Object related
PHP Version: 5.5.11 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: thierry at byscripts dot info
New email:
PHP Version: OS:


 [2014-04-18 21:17 UTC] thierry at byscripts dot info
I think we need to be able to allow traits to require that the class in which it can be used must be an instance of an arbitrary class/interface.

Expected result:
trait AirConditioning requires Vehicle
    public function increaseTemperature() { $this->ambientTemperature++; }
    public function decreaseTemperature() { $this->ambientTemperature--; }

abstract class Vehicle
    protected $ambientTemperature;

class Car extends Vehicle {}
class Truck extends Vehicle {}
class Dog extends Animal {}

class MyOldCar extends Car {}
class MyNewCar extends Car
    use AirConditioning; // Should be OK

class MyLabrador extends Dog
    use AirConditioning; // Should throw an exception


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-20 02:01 UTC]
My $0.02: allow traits to specify that they implement Interfaces. This is their #1 use already.
 [2017-09-10 21:10 UTC]
-Status: Open +Status: Suspended
 [2017-09-10 21:10 UTC]
Apparently, this proposal is controversial and as such would
require an RFC, see <>. Everybody is
welcome to create a respective RFC; if you do so please refer to
this feature request. In the meantime, I'm suspending this ticket.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 21:01:30 2024 UTC