-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic-object.php
More file actions
53 lines (36 loc) · 973 Bytes
/
static-object.php
File metadata and controls
53 lines (36 loc) · 973 Bytes
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
<?php
/*
static-object.php
*/
class MyClass {
function __construct() {
echo '<br/><span style="color:green; font-weight:bold;">Entered Constructor</span><br/><br/>';
}
public function func1() {
echo 'Entered Func 1<br/>';
return MyClass::findContext();
}
public function func2() {
echo 'Entered Func 2<br/>';
return MyClass::findContext();
}
public function func3() {
echo 'Entered Func 3<br/>';
return MyClass::findContext();
}
public function findContext() {
if(isset($this) && get_class($this) == __CLASS__ ) {
echo "Called Non-Statically<br/>";
return $this;
} else {
echo "Called Statically<br/>";
return new MyClass;
}
}
function __destruct() {
echo '<br/><span style="color:red; font-weight:bold;">Entered Destructor</span><br/><br/>';
}
}
class Model extends MyClass {
}
Model::func1()->func2()->func3();