note 113763 added to language.oop5.traits
| From: | peter at icb dot at | Date: | Thu, 28 Nov 2013 12:48:38 +0000 |
| Subject: | note 113763 added to language.oop5.traits | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197649@lists.php.net to get a copy of this message | ||
You cannot use a trait whos name is in a variable like:
<?php
trait mytrait { public $x; }
$tr = 'mytrait';
class myclass
{
use $tr;
...
}
?>
If you really need that, you have to use eval:
<?php
eval("
class my_tmp_class { use $tr; }
");
class myclass extends my_tmp_class { ... }
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/language.oop5.traits.php
Edit -- https://master.php.net/note/edit/113763
Del: integrated -- https://master.php.net/note/delete/113763/integrated
Del: useless -- https://master.php.net/note/delete/113763/useless
Del: bad code -- https://master.php.net/note/delete/113763/bad+code
Del: spam -- https://master.php.net/note/delete/113763/spam
Del: non-english -- https://master.php.net/note/delete/113763/non-english
Del: in docs -- https://master.php.net/note/delete/113763/in+docs
Del: other reasons-- https://master.php.net/note/delete/113763
Reject -- https://master.php.net/note/reject/113763
Search -- https://master.php.net/manage/user-notes.php