-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchaining.php
61 lines (47 loc) · 1.01 KB
/
chaining.php
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
61
<?php
echo "<h1>Method Chaining</h1>";
echo "Basic of Chaining";
class Abc
{
public $a = 1;
public function A()
{
echo "Method A";
// echo ++$this->a . "<br/>";
return $this; // if we reurn $this from here than method B() will able to access $ObjS
}
public function B()
{
echo "Method B";
// echo ++$this->a . "<br/>";
return $this; //similarly here too return $this
}
public function C()
{
echo "Method C";
// echo ++$this->a . "<br/>";
return $this; //similarly here too return $this
}
}
$ObjS = new Abc();
$ObjS->A()
->B()
->C();
//Example 2:
echo "<h1>Method Chaining example 2</h1>";
class Uploader
{
private $result;
public function afterSave($result)
{
$this->result = $result;
return $this;
}
public function calculateResult()
{
return $this->result * 4;
}
}
$a = new Uploader();
$result = 10;
echo $a->afterSave($result)->calculateResult();