1 | <?php |
||
32 | class FileHandler extends ObjectAbstract implements SessionHandlerInterface |
||
33 | { |
||
34 | /** |
||
35 | * storage path |
||
36 | * |
||
37 | * @var string |
||
38 | * @access protected |
||
39 | */ |
||
40 | protected $path; |
||
41 | |||
42 | /** |
||
43 | * session file prefix |
||
44 | * |
||
45 | * @var string |
||
46 | * @access protected |
||
47 | */ |
||
48 | protected $prefix; |
||
49 | |||
50 | /** |
||
51 | * Constructor |
||
52 | * |
||
53 | * @param string $path |
||
54 | * @access public |
||
55 | */ |
||
56 | public function __construct($path = '', $prefix = 'sess_') |
||
69 | |||
70 | /** |
||
71 | * {@inheritDoc} |
||
72 | * |
||
73 | * @return bool |
||
74 | * @see SessionHandlerInterface::close() |
||
75 | */ |
||
76 | public function close()/*# : bool */ |
||
80 | |||
81 | /** |
||
82 | * {@inheritDoc} |
||
83 | * |
||
84 | * @param string $session_id |
||
85 | * @return bool |
||
86 | * @see SessionHandlerInterface::destroy() |
||
87 | */ |
||
88 | public function destroy(/*# string */ $session_id)/*# : bool */ |
||
93 | |||
94 | /** |
||
95 | * {@inheritDoc} |
||
96 | * |
||
97 | * @param int $maxlifetime |
||
98 | * @return bool |
||
99 | * @see SessionHandlerInterface::gc() |
||
100 | */ |
||
101 | public function gc(/*# int */ $maxlifetime)/*# : bool */ |
||
105 | |||
106 | /** |
||
107 | * {@inheritDoc} |
||
108 | * |
||
109 | * @param string $save_path |
||
110 | * @param string $session_name |
||
111 | * @return bool |
||
112 | * @see SessionHandlerInterface::open() |
||
113 | */ |
||
114 | public function open( |
||
120 | |||
121 | /** |
||
122 | * {@inheritDoc} |
||
123 | * |
||
124 | * @param string $session_id |
||
125 | * @return string |
||
126 | * @see SessionHandlerInterface::read() |
||
127 | */ |
||
128 | public function read(/*# string */ $session_id)/*# : string */ |
||
137 | |||
138 | /** |
||
139 | * {@inheritDoc} |
||
140 | * |
||
141 | * @param string $session_id |
||
142 | * @param string $session_data |
||
143 | * @return bool |
||
144 | * @see SessionHandlerInterface::write() |
||
145 | */ |
||
146 | public function write( |
||
153 | |||
154 | /** |
||
155 | * Return the file path |
||
156 | * |
||
157 | * @param string $session_id |
||
158 | * @return string |
||
159 | * @access protected |
||
160 | */ |
||
161 | protected function getSessionFile(/*# string */ $session_id)/*# : string */ |
||
165 | } |
||
166 |
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.