-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraits.php
More file actions
60 lines (57 loc) · 1.36 KB
/
traits.php
File metadata and controls
60 lines (57 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class ParentE {
public function __construct() {echo "constructed ParentE \n";}
public function Ea() { echo "used extEa \n"; }
public function Eb() { echo "used extEb \n"; }
public function methodA() { echo "used extMethodA \n"; }
}
trait TraitC {
protected function traitCa() { echo "used traitCa \n"; }
protected function traitCb() { echo "used traitCb \n"; }
}
trait TraitD {
protected function traitDa() { echo "used traitDa \n"; }
protected function traitDb() { echo "used traitDa \n"; }
protected function methodA() { echo "used traitMethodA \n"; }
}
class A extends ParentE {
use TraitC;
use TraitD;
public function __construct() {echo "constructed A \n";}
public function a() {echo "used Aa \n";}
}
class B extends ParentE {
use TraitC;
public function __construct() {echo "constructed B \n";}
public function a() {echo "used Ba \n";}
}
$A = new A(); $B = new B();
echo "A--------\n";
$A->a();
$A->traitCa();
$A->traitCb();
$A->traitDa();
$A->traitDb();
$A->methodA();
$A->Ea();
$A->Eb();
echo "B--------\n";
$B->a();
$B->traitCa();
$B->traitCb();
$B->Ea();
$B->Eb();
echo "inst-------\n";
try
{
$ParentE = new ParentE();
$ParentE->Ea();
$ParentE->Eb();
$C = new C();
$C->traitCa();
$C->traitCb();
}
catch (Exception $e)
{
echo "Nope: [" . $e->getCode() . "]: ". $e->getMessage();
}