Req #65162 [Com]: Add Generics support

From: Date: Fri, 02 Jul 2021 08:39:38 +0000
Subject: Req #65162 [Com]: Add Generics support
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234756@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65162&edit=1 ID: 65162 Comment by: fcolecumberri at hotmail dot com Reported by: matutetandil at gmail dot com Summary: Add Generics support Status: Open Type: Feature/Change Request Package: Class/Object related Operating System: Any PHP Version: Irrelevant Block user comment: N Private report: N New Comment: smething like this??: <?php class MyClassA {} class MyClassB {} class MyClassC {} class MyGenericClass { public $object; public function __construct($T) { $this->object = new $T(); } } $mgc_a = new MyGenericClass(MyClassA::class); $mgc_b = new MyGenericClass(MyClassB::class); $mgc_c = new MyGenericClass(MyClassC::class); echo get_class($mgc_a->object)."\n"; echo get_class($mgc_b->object)."\n"; echo get_class($mgc_c->object)."\n"; Previous Comments: ------------------------------------------------------------------------ [2016-09-07 18:32:32] php at mattjanssen dot com There is a $1,000 bounty on this request: <https://www.bountysource.com/issues/20553561-add-generics-support>. ------------------------------------------------------------------------ [2016-06-21 20:15:29] cmb@php.net FWIW, there is a respective RFC in draft status: <https://wiki.php.net/rfc/generics>. ------------------------------------------------------------------------ [2013-06-28 18:17:11] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65162&edit=1

« previous php.bugs (#234756) next »