1 | <?php |
||
12 | class TransactionInput extends Serializable implements TransactionInputInterface |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var OutPointInterface |
||
17 | */ |
||
18 | private $outPoint; |
||
19 | |||
20 | /** |
||
21 | * @var ScriptInterface |
||
22 | */ |
||
23 | private $script; |
||
24 | |||
25 | /** |
||
26 | * @var string|int |
||
27 | */ |
||
28 | private $sequence; |
||
29 | |||
30 | /** |
||
31 | * @param OutPointInterface $outPoint |
||
32 | * @param ScriptInterface $script |
||
33 | * @param int $sequence |
||
34 | */ |
||
35 | 1368 | public function __construct(OutPointInterface $outPoint, ScriptInterface $script, $sequence = self::SEQUENCE_FINAL) |
|
36 | { |
||
37 | 1368 | $this->outPoint = $outPoint; |
|
38 | 1368 | $this->script = $script; |
|
39 | 1368 | $this->sequence = $sequence; |
|
40 | 1368 | } |
|
41 | |||
42 | /** |
||
43 | * @return OutPointInterface |
||
44 | */ |
||
45 | 1338 | public function getOutPoint() |
|
46 | { |
||
47 | 1338 | return $this->outPoint; |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * @return ScriptInterface |
||
52 | */ |
||
53 | 1366 | public function getScript() |
|
57 | |||
58 | /** |
||
59 | * @return int |
||
60 | */ |
||
61 | 1334 | public function getSequence() |
|
65 | |||
66 | /** |
||
67 | * @param TransactionInputInterface $other |
||
68 | * @return bool |
||
69 | */ |
||
70 | 16 | public function equals(TransactionInputInterface $other) |
|
82 | |||
83 | /** |
||
84 | * Check whether this transaction is a Coinbase transaction |
||
85 | * |
||
86 | * @return boolean |
||
87 | */ |
||
88 | 4 | public function isCoinbase() |
|
94 | |||
95 | /** |
||
96 | * @return bool |
||
97 | */ |
||
98 | 2 | public function isFinal() |
|
103 | |||
104 | /** |
||
105 | * @return int |
||
106 | */ |
||
107 | 2 | public function isSequenceLockDisabled() |
|
115 | |||
116 | /** |
||
117 | * @return bool |
||
118 | */ |
||
119 | public function isLockedToTime() |
||
123 | |||
124 | /** |
||
125 | * @return bool |
||
126 | */ |
||
127 | public function isLockedToBlock() |
||
131 | |||
132 | /** |
||
133 | * @return int |
||
134 | */ |
||
135 | public function getRelativeTimeLock() |
||
144 | |||
145 | /** |
||
146 | * @return int |
||
147 | */ |
||
148 | public function getRelativeBlockLock() |
||
156 | |||
157 | /** |
||
158 | * @return BufferInterface |
||
159 | */ |
||
160 | public function getBuffer() |
||
164 | } |
||
165 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.