note 116895 added to language.oop5.traits
| From: | 84td84 at gmail dot com | Date: | Tue, 17 Mar 2015 01:46:25 +0000 |
| Subject: | note 116895 added to language.oop5.traits | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201966@lists.php.net to get a copy of this message | ||
A note to 'Beispiel #9 Statische Variablen'. A trait can also have a static property:
trait Counter {
static $trvar=1;
public static function stfunc() {
echo "Hello world!"
}
}
class C1 {
use Counter;
}
print "\nTRVAR: " . C1::$trvar . "\n"; //prints 1
$obj = new C1();
C1::stfunc(); //prints Hello world!
$obj->stfunc(); //prints Hello world!
A static property (trvar) can only be accessed using the classname (C1).
But a static function (stfunc) can be accessed using the classname or the instance ($obj).
----
Server IP: 72.52.91.14
Probable Submitter: 86.33.71.83
----
Manual Page -- http://php.net/manual/en/language.oop5.traits.php
Edit -- https://master.php.net/note/edit/116895
Del: integrated -- https://master.php.net/note/delete/116895/integrated
Del: useless -- https://master.php.net/note/delete/116895/useless
Del: bad code -- https://master.php.net/note/delete/116895/bad+code
Del: spam -- https://master.php.net/note/delete/116895/spam
Del: non-english -- https://master.php.net/note/delete/116895/non-english
Del: in docs -- https://master.php.net/note/delete/116895/in+docs
Del: other reasons-- https://master.php.net/note/delete/116895
Reject -- https://master.php.net/note/reject/116895
Search -- https://master.php.net/manage/user-notes.php