note 109508 added to language.oop5.traits
| From: | t8 at ATpobox dot com | Date: | Mon, 23 Jul 2012 20:17:16 +0000 |
| Subject: | note 109508 added to language.oop5.traits | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189377@lists.php.net to get a copy of this message | ||
Another difference with traits vs inheritance is that methods defined in traits can access methods
and properties of the class they're used in, including private ones.
For example:
<?php
trait MyTrait
{
protected function accessVar()
{
return $this->var;
}
}
class TraitUser
{
use MyTrait;
private $var = 'var';
public function getVar()
{
return $this->accessVar();
}
}
$t = new TraitUser();
echo $t->getVar(); // -> 'var'
?>
----
Server IP: 208.69.120.55
Probable Submitter: 72.148.34.248
----
Manual Page -- http://www.php.net/manual/en/language.oop5.traits.php
Edit -- https://master.php.net/note/edit/109508
Del: integrated -- https://master.php.net/note/delete/109508/integrated
Del: useless -- https://master.php.net/note/delete/109508/useless
Del: bad code -- https://master.php.net/note/delete/109508/bad+code
Del: spam -- https://master.php.net/note/delete/109508/spam
Del: non-english -- https://master.php.net/note/delete/109508/non-english
Del: in docs -- https://master.php.net/note/delete/109508/in+docs
Del: other reasons-- https://master.php.net/note/delete/109508
Reject -- https://master.php.net/note/reject/109508
Search -- https://master.php.net/manage/user-notes.php