|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 18 01:00:01 2025 UTC |
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";