php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65162 Add Generics support
Submitted: 2013-06-28 18:17 UTC Modified: 2016-06-21 20:15 UTC
Votes:55
Avg. Score:4.7 ± 0.8
Reproduced:38 of 38 (100.0%)
Same Version:26 (68.4%)
Same OS:26 (68.4%)
From: matutetandil at gmail dot com Assigned:
Status: Open Package: Class/Object related
PHP Version: Irrelevant OS: Any
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: matutetandil at gmail dot com
New email:
PHP Version: OS:

 

 [2013-06-28 18:17 UTC] matutetandil at gmail dot com
Description:
------------
Add generics support to PHP. So you can declare classes like this:

class MyGenericClass<T> {
   private $object;

   public function __construct() {
       $this->object = new T();
   }
}

or

class MyGenericClass<T extends SuperTClass> {
   private $object;

   public function __construct() {
       $this->object = new T();
   }
}

In the first case you can make a new (supposing that there is defined a B 
class):
$a = new MyGenericClass<B>();

and in the second example you are forcing B to be a SuperTClass.

I hope you can implement this feature! Is great!!!

Expected result:
----------------
Generics included in a PHP relase.

Actual result:
--------------
No Generics support.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-21 20:15 UTC] cmb@php.net
FWIW, there is a respective RFC in draft status:
<https://wiki.php.net/rfc/generics>.
 [2016-09-07 18:32 UTC] php at mattjanssen dot com
There is a $1,000 bounty on this request: <https://www.bountysource.com/issues/20553561-add-generics-support>.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri May 24 15:01:26 2019 UTC