Req #67097 [Opn]: Allow traits to require class/interface

From: Date: Sun, 20 Apr 2014 02:01:18 +0000
Subject: Req #67097 [Opn]: Allow traits to require class/interface
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185345@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67097&edit=1 ID: 67097 Updated by: levim@php.net Reported by: thierry at byscripts dot info Summary: Allow traits to require class/interface Status: Open Type: Feature/Change Request Package: Class/Object related PHP Version: 5.5.11 Block user comment: N Private report: N New Comment: My $0.02: allow traits to specify that they implement Interfaces. This is their #1 use already. Previous Comments: ------------------------------------------------------------------------ [2014-04-18 21:17:31] 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 } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67097&edit=1

« previous php.bugs (#185345) next »