trait, interface, abstract, class inheritance in PHP

In trait definition, how to define static class variables and methods, please take a look as below:

1 <?php
2 trait testTrait {
3   private static $sAbc='s123';
4   private $abc='123';
5   public static function sfAbc() {
6     print static::$sAbc;
7   }
8   public function fAbc() {
9     print $this->abc;
10   }
11 }
12
13 class TraitTest {
14   use testTrait;
15 }
16
17 TraitTest::sfAbc();
18 $tt = new TraitTest();
19 $tt->fAbc();

interface can inherit(extends not implements) more interfaces,

1 <?php
2 interface abc {
3   public function hello();
4 }
5
6 interface abcd {
7   public function helloworld();
8 }
9
10 interface bcd extends abc,abcd {
11   public function world();
12 }
13
14 class cde implements bcd {
15   public function hello() {
16     print 'hello ';
17   }
18   public function world() {
19     print 'world ';
20   }
21   public function helloworld() {
22     print 'hello world';
23   }
24 }
25
26 class def {
27   public function blabla() {
28     print 'blabla ';
29   }
30 }
31
32 class efg extends cde {  //can not add more extends class, will be error
33   public function test() {
34   }
35 }

Tell others about me!

Leave a Reply

Your email address will not be published. Required fields are marked *