{"id":411175,"date":"2024-06-29T21:49:09","date_gmt":"2024-06-29T21:49:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=411175"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=411175","title":{"rendered":"<span>PHP Generics. Right here. Right now<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/_x\/ey\/w6\/_xeyw6-xutglqjdkkumytrmgcl4.png\" data-src=\"https:\/\/habrastorage.org\/webt\/_x\/ey\/w6\/_xeyw6-xutglqjdkkumytrmgcl4.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 PHP \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u0432 PHP \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Generic_programming\" rel=\"nofollow noopener noreferrer\">\u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432<\/a>, \u0438 \u044f \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435. <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\" rel=\"nofollow noopener noreferrer\">RFC<\/a> \u043f\u043e \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0435\u0449\u0451 \u0432 2016 \u0433\u043e\u0434\u0443, \u043d\u043e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043f\u0440\u0438\u043d\u044f\u043b \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434. \u042f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u0432 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0435 PHP, \u043d\u043e \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0433 \u0431\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043c\u043e\u0433\u0443 \u0441\u0430\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 PHP. \u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0432\u044b\u0448\u0435 \u2014 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0432\u043e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/mrsuh\/php-generics\" rel=\"nofollow noopener noreferrer\">mrsuh\/php-generics<\/a> \u0438 <a href=\"https:\/\/github.com\/mrsuh\/php-generics-example\" rel=\"nofollow noopener noreferrer\">\u0440\u0435\u043f\u043e<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043c\u043e\u043d\u043e\u043c\u043e\u0440\u0444\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0426\u0438\u0442\u0430\u0442\u0430 <a href=\"https:\/\/habr.com\/ru\/company\/skyeng\/blog\/543794\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>. \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b <a href=\"https:\/\/www.reddit.com\/r\/PHP\/comments\/j65968\/ama_with_the_phpstorm_team_from_jetbrains_on\/g83skiz\/?context=3\" rel=\"nofollow noopener noreferrer\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u043c, \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432: + Type-erasure (\u0441\u0442\u0438\u0440\u0430\u0435\u043c\u044b\u0435): \u0414\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438 Foo&lt;T> \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f Foo. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u043d\u0438 \u043d\u0430 \u0447\u0442\u043e \u043d\u0435 \u0432\u043b\u0438\u044f\u044e\u0442, \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438\/\u0430\u043d\u0430\u043b\u0438\u0437\u0430 (\u043f\u0440\u0438\u043c. Python, TypeScript). + Reification (\u0440\u0435\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f): \u0414\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b (\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 PHP, \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u044b \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435). + Monomorphization (\u043c\u043e\u043d\u043e\u043c\u043e\u0440\u0444\u0438\u0437\u0430\u0446\u0438\u044f): \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0440\u0435\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043d\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u0422\u043e \u0435\u0441\u0442\u044c, Foo&lt;T> \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0447\u0442\u043e, \u043a\u043b\u0430\u0441\u0441 Foo \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c T, \u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u044b Foo_T1, Foo_T2, \u2026, Foo_Tn \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"kak-rabotaet\">\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h2>\n<p>  <\/p>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u0430\u0440\u0441\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432;<\/li>\n<li>\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430 \u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b;<\/li>\n<li>\u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f composer autoload, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0438\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u2014 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c.<\/p>\n<p>  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u0430\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c composer (\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f PHP 7.4).<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">composer require mrsuh\/php-generics<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e (&#171;cache\/&#187;) \u0432 composer autoload PSR-4 \u0434\u043b\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<br \/>  \u041e\u043d\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u0434\u0442\u0438 \u043f\u0435\u0440\u0435\u0434 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0435\u0439.<br \/>  composer.json<\/p>\n<p>  <\/p>\n<pre><code class=\"json\">{    \"autoload\": {        \"psr-4\": {            \"App\\\\\": [\"cache\/\",\"src\/\"]        }    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e PHP \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043a\u043b\u0430\u0441\u0441 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a <code>Box<\/code>;<\/li>\n<li>\u043a\u043b\u0430\u0441\u0441 <code>Usage<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442;<\/li>\n<li>\u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 composer <code>autoload<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 <code>Usage<\/code>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>src\/Box.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Box&lt;T> {     private ?T $data = null;     public function set(T $data): void {        $this->data = $data;    }     public function get(): ?T {        return $this->data;    } }<\/code><\/pre>\n<p>  <\/p>\n<p>src\/Usage.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Usage {     public function run(): void    {        $stringBox = new Box&lt;string>();        $stringBox->set('cat');        var_dump($stringBox->get()); \/\/ string \"cat\"         $intBox = new Box&lt;int>();        $intBox->set(1);        var_dump($intBox->get()); \/\/ integer 1    } }<\/code><\/pre>\n<p>  <\/p>\n<p>bin\/test.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  require_once __DIR__ . '\/..\/vendor\/autoload.php';  use App\\Usage;  $usage = new Usage(); $usage->run();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>composer dump-generics<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">composer dump-generics -v Generating concrete classes  - App\\BoxForString  - App\\BoxForInt  - App\\Usage Generated 3 concrete classes in 0.062 seconds, 16.000 MB memory used<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 <code>composer dump-generics<\/code>:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 (\u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0444\u0430\u0439\u043b\u043e\u043c <code>src\/Usage.php<\/code>);<\/li>\n<li>\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u043b\u044f \u043d\u0438\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 (\u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u043c\u0435\u043d\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432) \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432;<\/li>\n<li>\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0432 \u043c\u0435\u0441\u0442\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li>2 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 <code>BoxForInt<\/code> \u0438 <code>BoxForString<\/code>;<\/li>\n<li>1 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>Usage<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u0437\u0430\u043c\u0435\u043d\u0435\u043d\u044b \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>cache\/BoxForInt.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class BoxForInt {    private ?int $data = null;     public function set(int $data) : void    {        $this->data = $data;    }     public function get() : ?int    {        return $this->data;    } }<\/code><\/pre>\n<p>  <\/p>\n<p>cache\/BoxForString.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class BoxForString {    private ?string $data = null;     public function set(string $data) : void    {        $this->data = $data;    }     public function get() : ?string    {        return $this->data;    } }<\/code><\/pre>\n<p>  <\/p>\n<p>cache\/Usage.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Usage {    public function run() : void    {        $stringBox = new \\App\\BoxForString();        $stringBox->set('cat');        var_dump($stringBox->get());\/\/ string \"cat\"         $intBox = new \\App\\BoxForInt();        $intBox->set(1);        var_dump($intBox->get());\/\/ integer 1    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 vendor\/autoload.php \u0444\u0430\u0439\u043b \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>composer dump-autoload<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">composer dump-autoload Generating autoload files Generated autoload files<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">php bin\/test.php<\/code><\/pre>\n<p>  <\/p>\n<p>Composer autoload \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 &#171;cache&#187;, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 &#171;src&#187;.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043a\u043e\u0434\u043e\u043c \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/mrsuh\/php-generics-example\" rel=\"nofollow noopener noreferrer\">\u0442\u0443\u0442<\/a>.<br \/>  \u0411\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/mrsuh\/php-generics\/tests\" rel=\"nofollow noopener noreferrer\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"osobennosti-realizacii\">\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<h4 id=\"kakoy-sintaksis-ispolzuetsya\">\u041a\u0430\u043a\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f?<\/h4>\n<p>  <\/p>\n<p>\u0412 <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\" rel=\"nofollow noopener noreferrer\">RFC<\/a> \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0432\u0437\u044f\u043b <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\/issues\/45\" rel=\"nofollow noopener noreferrer\">\u0442\u043e\u0442<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b \u041d\u0438\u043a\u0438\u0442\u0430 \u041f\u043e\u043f\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Generic&lt;in T: Iface = int, out V: Iface = string> {     public function test(T $var): V {     } }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"problemy-s-sintaksisom\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c<\/h4>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043a\u043e\u0434\u0430 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u043e\u043f\u0438\u043b\u0438\u0442\u044c <a href=\"https:\/\/github.com\/nikic\/PHP-Parser\" rel=\"nofollow noopener noreferrer\">nikic\/php-parser<\/a>. \u0412\u043e\u0442 <a href=\"https:\/\/github.com\/mrsuh\/PHP-Parser\/pull\/1\/files#diff-14ec37995c001c0c9808ab73668d64db5d1acc1ab0f60a360dcb9c611ecd57ea\" rel=\"nofollow noopener noreferrer\">\u0442\u0443\u0442<\/a> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0432\u043d\u0435\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432. \u0412\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/ircmaxell\/PHP-Yacc\" rel=\"nofollow noopener noreferrer\">PHP \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a> <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Yacc\" rel=\"nofollow noopener noreferrer\">YACC<\/a>. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 YACC (LALR) \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 PHP \u043d\u0435 \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0435\u0449\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0438 \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  const FOO = 'FOO'; const BAR = 'BAR';  var_dump(new \\DateTime&lt;FOO, BAR>('now')); \/\/ \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a var_dump( (new \\DateTime &lt; FOO) , ( BAR > 'now') ); \/\/ \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\/issues\/35#issuecomment-571546650\" rel=\"nofollow noopener noreferrer\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Usage {    public function run() {        $map = new Map&lt;Key&lt;int>, Value&lt;string>>();\/\/\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f    } }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"imena-parametrov-ne-imeyut-kakih-to-specialnyh-ogranicheniy\">\u0418\u043c\u0435\u043d\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439<\/h4>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class GenericClass&lt;T, varType, myCoolLongParaterName> {    private T $var1;    private varType $var2;    private myCoolLongParaterName $var3;    }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"mozhno-ispolzovat-neskolko-parametrov-v-dzhenerikah\">\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430\u0445<\/h4>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Map&lt;keyType, valueType> {     private array $map;     public function set(keyType $key, valueType $value): void {        $this->map[$key] = $value;    }     public function get(keyType $key): ?valueType {        return $this->map[$key] ?? null;    } }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"mozhno-ispolzovat-znacheniya-po-umolchaniyu\">\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h4>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Map&lt;keyType = string, valueType = int> {     private array $map = [];     public function set(keyType $key, valueType $value): void {        $this->map[$key] = $value;    }     public function get(keyType $key): ?valueType {        return $this->map[$key] ?? null;    } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Usage {    public function run() {        $map = new Map&lt;>();\/\/\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u043a\u0438 \"&lt;>\"        $map->set('key', 1);        var_dump($map->get('key'));    } }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"v-kakom-meste-klassa-mozhno-ispolzovat-dzheneriki\">\u0412 \u043a\u0430\u043a\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438?<\/h4>\n<p>  <\/p>\n<ul>\n<li>extends<\/li>\n<li>implements<\/li>\n<li>trait use<\/li>\n<li>property type<\/li>\n<li>method argument type<\/li>\n<li>method return type<\/li>\n<li>instanceof<\/li>\n<li>new<\/li>\n<li>class constants<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  use App\\Entity\\Cat; use App\\Entity\\Bird; use App\\Entity\\Dog;  class Test extends GenericClass&lt;Cat> implements GenericInterface&lt;Bird> {    use GenericTrait&lt;Dog>;    private GenericClass&lt;int>|GenericClass&lt;Dog> $var;    public function test(GenericInterface&lt;int>|GenericInterface&lt;Dog> $var): GenericClass&lt;string>|GenericClass&lt;Bird> {         var_dump($var instanceof GenericInterface&lt;int>);         var_dump(GenericClass&lt;int>::class);         var_dump(GenericClass&lt;array>::CONSTANT);         return new GenericClass&lt;float>();   } }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"v-kakom-meste-klassa-dzhenerika-mozhno-ispolzovat-parametry-dzhenerikov\">\u0412 \u043a\u0430\u043a\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432?<\/h4>\n<p>  <\/p>\n<ul>\n<li>extends<\/li>\n<li>implements<\/li>\n<li>trait use<\/li>\n<li>property type<\/li>\n<li>method argument type<\/li>\n<li>method return type<\/li>\n<li>instanceof<\/li>\n<li>new<\/li>\n<li>class constants<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Test&lt;T,V> extends GenericClass&lt;T> implements GenericInterface&lt;V> {    use GenericTrait&lt;T>;   use T;    private T|GenericClass&lt;V> $var;    public function test(T|GenericInterface&lt;V> $var): T|GenericClass&lt;V> {         var_dump($var instanceof GenericInterface&lt;V>);         var_dump($var instanceof T);         var_dump(GenericClass&lt;T>::class);         var_dump(T::class);         var_dump(GenericClass&lt;T>::CONSTANT);         var_dump(T::CONSTANT);         $obj1 = new T();        $obj2 = new GenericClass&lt;V>();         return $obj2;   } }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"naskolko-bystro-rabotaet\">\u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h4>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u0438 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c).<\/p>\n<p>  <\/p>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0440\u0435\u0437\u043e\u043b\u0432\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432;<\/li>\n<li>\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438;<\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u0432\u0441\u0451 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e, \u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>  <\/p>\n<h4 id=\"nelzya-ispolzovat-bez-composer-autoload\">\u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 composer autoload<\/h4>\n<p>  <\/p>\n<p>\u041c\u0430\u0433\u0438\u044f \u0441 \u0430\u0432\u0442\u043e\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 composer autoload.<br \/>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u043a\u043b\u0430\u0441\u0441 \u0441 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u043c \u0447\u0435\u0440\u0435\u0437 require, \u0442\u043e \u0443 \u0432\u0430\u0441 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0437-\u0437\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430.<br \/>  PhpUnit \u043f\u043e <a href=\"https:\/\/github.com\/sebastianbergmann\/phpunit\/issues\/4039\" rel=\"nofollow noopener noreferrer\">\u0441\u0432\u043e\u0438\u043c \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c<\/a> \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0444\u0430\u0439\u043b\u044b \u0442\u0435\u0441\u0442\u043e\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 require.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 PhpUnit \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<h4 id=\"ide\">IDE<\/h4>\n<p>  <\/p>\n<ul>\n<li>\n<p>PhpStorm<br \/>  \u041d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u0430\u0436\u0435 <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\" rel=\"nofollow noopener noreferrer\">RFC<\/a> \u0435\u0449\u0451 \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d.<br \/>  \u0422\u0430\u043a\u0436\u0435 PhpStorm \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e <a href=\"https:\/\/plugins.jetbrains.com\/plugin\/10209-lsp-support\" rel=\"nofollow noopener noreferrer\">\u043f\u043b\u0430\u0433\u0438\u043d\u0430<\/a> \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <a href=\"https:\/\/en.wikipedia.org\/wiki\/Language_Server_Protocol\" rel=\"nofollow noopener noreferrer\">LSP<\/a>, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u044b \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432.<br \/>  \u041e\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <a href=\"https:\/\/hacklang.org\" rel=\"nofollow noopener noreferrer\">Hack<\/a> (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438) <a href=\"https:\/\/blog.jetbrains.com\/phpstorm\/2015\/06\/hack-language-support-in-phpstorm-postponed\/\" rel=\"nofollow noopener noreferrer\">\u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c<\/a>.<\/p>\n<p>  <\/li>\n<li>\n<p>VSCode<br \/>  \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=pranayagarwal.vscode-hack\" rel=\"nofollow noopener noreferrer\">\u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0434\u043b\u044f Hack<\/a>.<br \/>  \u041d\u0435\u0442 \u0430\u0432\u0442\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/li>\n<\/ul>\n<p>  <\/p>\n<h4 id=\"reflection\">Reflection<\/h4>\n<p>  <\/p>\n<p>PHP \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432 <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\/issues\/43\" rel=\"nofollow noopener noreferrer\">runtime<\/a>. \u0417\u043d\u0430\u0447\u0438\u0442, \u0432\u0441\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\/blob\/cc7219792a5b35226129d09536789afe20eac029\/generics.txt#L426-L430\" rel=\"nofollow noopener noreferrer\">\u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b<\/a> \u0447\u0435\u0440\u0435\u0437 reflection \u0432 runtime. \u0410 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u0442\u0438\u0440\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<h2 id=\"chto-ne-realizovano-po-rfc\">\u0427\u0442\u043e \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u043f\u043e RFC<\/h2>\n<p>  <\/p>\n<h4 id=\"dzheneriki-funkciy-anonimnyh-funkciy-i-metodov\">\u0414\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/h4>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  function foo&lt;T,V>(T $arg): V {  }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"proverka-tipov-parametrov-dzhenerikov\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432<\/h4>\n<p>  <\/p>\n<p>T \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0438\u043b\u0438 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 TInterface.<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Generic&lt;T: TInterface> {  }<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"variantnost-parametrov\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/h4>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App;  class Generic&lt;in T, out V> {  }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"suschestvuyuschie-resheniya-na-php\">\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 PHP<\/h2>\n<p>  <\/p>\n<h4 id=\"psalm-template-annotationshttpspsalmdevdocsannotating_codetemplated_annotations\"><a href=\"https:\/\/psalm.dev\/docs\/annotating_code\/templated_annotations\/\" rel=\"nofollow noopener noreferrer\">Psalm Template Annotations<\/a><\/h4>\n<p>  <\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u044f\u0437\u044b\u043a\u0430;<\/li>\n<li>\u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438\/\u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438;<\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0438c\u0445\u043e\u0434\u044f\u0442 \u043f\u0440\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0435 <a href=\"https:\/\/psalm.dev\" rel=\"nofollow noopener noreferrer\">Psalm<\/a> \u0438\u043b\u0438 IDE.<\/li>\n<\/ul>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php \/** * @template T *\/ class MyContainer {  \/** @var T *\/  private $value;   \/** @param T $value *\/  public function __construct($value) {    $this->value = $value;  }   \/** @return T *\/  public function getValue() {    return $this->value;  } }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4 id=\"spatietypedhttpsgithubcomspatietyped\"><a href=\"https:\/\/github.com\/spatie\/typed\" rel=\"nofollow noopener noreferrer\">spatie\/typed<\/a><\/h4>\n<p>  <\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u044f\u0437\u044b\u043a\u0430;<\/li>\n<li>\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u043d\u043e \u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438;<\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u044f runtime.<\/li>\n<\/ul>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  $list = new Collection(T::bool());  $list[] = new Post(); \/\/ TypeError<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  $point = new Tuple(T::float(), T::float());  $point[0] = 1.5; $point[1] = 3;  $point[0] = 'a'; \/\/ TypeError $point['a'] = 1; \/\/ TypeError $point[10] = 1; \/\/ TypeError<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4 id=\"timetoogophp-genericshttpsgithubcomtimetoogophp-generics\"><a href=\"https:\/\/github.com\/TimeToogo\/PHP-Generics\" rel=\"nofollow noopener noreferrer\">TimeToogo\/PHP-Generics<\/a><\/h4>\n<p>  <\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u044f\u0437\u044b\u043a\u0430;<\/li>\n<li>\u0432\u0441\u0435 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f <strong>TYPE<\/strong> \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b, \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0424\u0421;<\/li>\n<li>\u043f\u043e\u0434\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u044f autoload \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 autoloader;<\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u044f runtime.<\/li>\n<\/ul>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  class Maybe {    private $MaybeValue;     public function __construct(__TYPE__ $Value = null) {        $this->MaybeValue = $Value;    }     public function HasValue() {        return $this->MaybeValue !== null;    }     public function GetValue() {        return $this->MaybeValue;    }     public function SetValue(__TYPE__ $Value = null) {        $this->MaybeValue = $Value;    } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  $Maybe = new Maybe\\stdClass(); $Maybe->HasValue(); \/\/false $Maybe->SetValue(new stdClass()); $Maybe->HasValue(); \/\/true $Maybe->SetValue(new DateTime()); \/\/ERROR<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  $Configuration = new \\Generics\\Configuration(); $Configuration->SetIsDevelopmentMode(true); $Configuration->SetRootPath(__DIR__); $Configuration->SetCachePath(__DIR__ . '\/Cache'); \/\/Register the generic auto loader \\Generics\\Loader::Register($Configuration);<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4 id=\"ircmaxellphpgenericshttpsgithubcomircmaxellphpgenerics\"><a href=\"https:\/\/github.com\/ircmaxell\/PhpGenerics\" rel=\"nofollow noopener noreferrer\">ircmaxell\/PhpGenerics<\/a><\/h4>\n<p>  <\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441;<\/li>\n<li>\u0432\u0441\u0435 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f T \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b, \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u0445 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 eval();<\/li>\n<li>\u043f\u043e\u0434\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u044f autoload, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 autoloader;<\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u044f runtime.<\/li>\n<\/ul>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<p>Test\/Item.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace test;  class Item&lt;T> {     protected $item;     public function __construct(T $item = null)    {        $this->item = $item;    }     public function getItem()    {        return $item;    }     public function setItem(T $item)    {        $this->item = $item;    } }<\/code><\/pre>\n<p>  <\/p>\n<p>Test\/Test.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace Test;  class Test {    public function runTest()    {        $item = new Item&lt;StdClass>;        var_dump($item instanceof Item); \/\/ true        $item->setItem(new StdClass); \/\/ works fine        \/\/ $item->setItem([]); \/\/ E_RECOVERABLE_ERROR    } }<\/code><\/pre>\n<p>  <\/p>\n<p>test.php<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  require \"vendor\/autoload.php\";  $test = new Test\\Test; $test->runTest();<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <a href=\"https:\/\/github.com\/mrsuh\/php-generics\" rel=\"nofollow noopener noreferrer\">mrsuh\/php-generics<\/a>:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f autoload;<\/li>\n<li>\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 eval();<\/li>\n<li>\u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 composer autoload;<\/li>\n<li>\u043a\u043e\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0434\u0430\u0432\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u0439 PHP.<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0414\u0443\u043c\u0430\u044e, \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0442\u043e, \u0447\u0435\u0433\u043e \u044f \u0445\u043e\u0442\u0435\u043b: \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043b\u0435\u0433\u043a\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u0420\u0430\u0441\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 IDE \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0432 \u043f\u043e\u043b\u043d\u043e\u0439 \u043c\u0435\u0440\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c \u0441\u043b\u043e\u0436\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 <a href=\"https:\/\/github.com\/mrsuh\/php-generics\/issues\" rel=\"nofollow noopener noreferrer\">\u0442\u0443\u0442<\/a> \u0438\u043b\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/577750\/\"> https:\/\/habr.com\/ru\/articles\/577750\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/_x\/ey\/w6\/_xeyw6-xutglqjdkkumytrmgcl4.png\" data-src=\"https:\/\/habrastorage.org\/webt\/_x\/ey\/w6\/_xeyw6-xutglqjdkkumytrmgcl4.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 PHP \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u0432 PHP \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Generic_programming\" rel=\"nofollow noopener noreferrer\">\u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432<\/a>, \u0438 \u044f \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435. <a href=\"https:\/\/github.com\/PHPGenerics\/php-generics-rfc\" rel=\"nofollow noopener noreferrer\">RFC<\/a> \u043f\u043e \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0435\u0449\u0451 \u0432 2016 \u0433\u043e\u0434\u0443, \u043d\u043e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043f\u0440\u0438\u043d\u044f\u043b \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434. \u042f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u0432 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0435 PHP, \u043d\u043e \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0433 \u0431\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043c\u043e\u0433\u0443 \u0441\u0430\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 PHP. \u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0432\u044b\u0448\u0435 \u2014 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0432\u043e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/mrsuh\/php-generics\" rel=\"nofollow noopener noreferrer\">mrsuh\/php-generics<\/a> \u0438 <a href=\"https:\/\/github.com\/mrsuh\/php-generics-example\" rel=\"nofollow noopener noreferrer\">\u0440\u0435\u043f\u043e<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-411175","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/411175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=411175"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/411175\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=411175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=411175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=411175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}