php.net |  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
Votes:4
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: thierry at byscripts dot info
New email:
PHP Version: OS:

 

 [2014-04-18 21:17 UTC] thierry at byscripts dot info
Description:
------------
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
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-20 02:01 UTC] levim@php.net
My $0.02: allow traits to specify that they implement Interfaces. This is their #1 use already.
 [2017-09-10 21:10 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2017-09-10 21:10 UTC] cmb@php.net
Apparently, this proposal is controversial and as such would
require an RFC, see <https://wiki.php.net/rfc>. 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: Sun Dec 22 02:01:28 2024 UTC