blob: 398403edafd905cf32a3ff29270569599f9eadd5 [file] [log] [blame]
Andrey Andreev81f03672014-02-13 17:57:41 +02001#######################
2Compatibility Functions
3#######################
4
5CodeIgniter provides a set of compatibility functions that enable
6you to use functions what are otherwise natively available in PHP,
7but only in higher versions or depending on a certain extension.
8
9Being custom implementations, these functions will also have some
10set of dependancies on their own, but are still useful if your
11PHP setup doesn't offer them natively.
12
13.. note:: Much like the `common functions <common_functions>`, the
14 compatibility functions are always available, as long as
15 their dependancies are met.
16
17.. contents::
18 :local:
19
20.. raw:: html
21
22 <div class="custom-index container"></div>
23
24****************
25Password Hashing
26****************
27
28This set of compatibility functions offers a "backport" of PHP's
29standard `Password Hashing extension <http://php.net/password>`_
30that is otherwise available only since PHP 5.5.
31
32Dependancies
33============
34
35- PHP 5.3.7
36- ``CRYPT_BLOWFISH`` support for ``crypt()``
37
38Constants
39=========
40
41- ``PASSWORD_BCRYPT``
42- ``PASSWORD_DEFAULT``
43
44Function reference
45==================
46
47.. function:: password_get_info($hash)
48
49 :param string $hash: Password hash
50 :returns: Information about the hashed password
51 :rtype: array
52
53 For more information, please refer to the `PHP manual for
54 password_get_info() <http://php.net/password_get_info>`_.
55
56.. function:: password_hash($password, $algo[, $options = array()])
57
58 :param string $password: Plain-text password
59 :param int $algo: Hashing algorithm
60 :param array $options: Hashing options
61 :returns: Hashed password or FALSE on failure
62 :rtype: string
63
64 For more information, please refer to the `PHP manual for
65 password_hash() <http://php.net/password_hash>`_.
66
67 .. note:: Unless you provide your own (and valid) salt, this function
68 has a further dependancy on an available CSPRNG source. Each
69 of the following would satisfy that:
70 - ``mcrypt_create_iv()`` with ``MCRYPT_DEV_URANDOM``
71 - ``openssl_random_pseudo_bytes()``
72 - /dev/arandom
73 - /dev/urandom
74
75.. function:: password_needs_rehash()
76
77 :param string $hash: Password hash
78 :param int $algo: Hashing algorithm
79 :param array $options: Hashing options
80 :returns: TRUE if the hash should be rehashed to match the given algorithm and options, FALSE otherwise
81 :rtype: bool
82
83 For more information, please refer to the `PHP manual for
84 password_needs_rehash() <http://php.net/password_needs_rehash>`_.
85
86.. function:: password_verify($password, $hash)
87
88 :param string $password: Plain-text password
89 :param string $hash: Password hash
90 :returns: TRUE if the password matches the hash, FALSE if not
91 :rtype: bool
92
93 For more information, please refer to the `PHP manual for
94 password_verify() <http://php.net/password_verify>`_.
95
Andrey Andreev9a152a92014-02-18 16:29:53 +020096*********************
97Hash (Message Digest)
98*********************
99
100This compatibility layer contains only a single function at
101this time - ``hash_pbkdf2()``, which otherwise requires PHP 5.5.
102
103Dependancies
104============
105
106- None
107
108Function reference
109==================
110
111.. function:: hash_pbkdf2($algo, $password, $salt, $iterations[, $length = 0[, $raw_output = FALSE]])
112
113 :param string $algo: Hashing algorithm
114 :param string $password: Password
115 :param string $salt: Hash salt
116 :param int $iterations: Number of iterations to perform during derivation
117 :param int $length: Output string length
118 :param bool $raw_output: Whether to return raw binary data
119 :returns: Password-derived key or FALSE on failure
120 :rtype: string
121
122 For more information, please refer to the `PHP manual for
123 hash_pbkdf2() <http://php.net/hash_pbkdf2>`_.
124
Andrey Andreev81f03672014-02-13 17:57:41 +0200125****************
126Multibyte String
127****************
128
129This set of compatibility functions offers limited support for PHP's
130`Multibyte String extension <http://php.net/mbstring>`_. Because of
131the limited alternative solutions, only a few functions are available.
132
133.. note:: When a character set parameter is ommited,
134 ``$config['charset']`` will be used.
135
136Dependancies
137============
138
139- `iconv <http://php.net/iconv>`_ extension
140
141.. important:: This dependancy is optional and these functions will
142 always be declared. If iconv is not available, they WILL
143 fall-back to their non-mbstring versions.
144
145.. important:: Where a character set is supplied, it must be
146 supported by iconv and in a format that it recognizes.
147
148.. note:: For you own dependancy check on the actual mbstring
149 extension, use the ``MB_ENABLED`` constant.
150
151Function reference
152==================
153
154.. function:: mb_strlen($str[, $encoding = NULL])
155
156 :param string $str: Input string
157 :param string $encoding: Character set
158 :returns: Number of characters in the input string or FALSE on failure
159 :rtype: string
160
161 For more information, please refer to the `PHP manual for
162 mb_strlen() <http://php.net/mb_strlen>`_.
163
164.. function:: mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]])
165
166 :param string $haystack: String to search in
167 :param string $needle: Part of string to search for
168 :param int $offset: Search offset
169 :param string $encoding: Character set
170 :returns: Numeric character position of where $needle was found or FALSE if not found
171 :rtype: mixed
172
173 For more information, please refer to the `PHP manual for
174 mb_strpos() <http://php.net/mb_strpos>`_.
175
176.. function:: mb_substr($str, $start[, $length = NULL[, $encoding = NULL]])
177
178 :param string $str: Input string
179 :param int $start: Position of first character
180 :param int $length: Maximum number of characters
181 :param string $encoding: Character set
182 :returns: Portion of $str specified by $start and $length or FALSE on failure
183 :rtype: string
184
185 For more information, please refer to the `PHP manual for
Andrey Andreev02545892014-02-19 23:49:31 +0200186 mb_substr() <http://php.net/mb_substr>`_.
187
188***************
189Array Functions
190***************
191
192This set of compatibility functions offers support for a few
193standard `Array Functions <http://php.net/book.array>`_ in PHP
194that otherwise require a newer PHP version.
195
196Dependancies
197============
198
199- None
200
201Function reference
202==================
203
204.. function:: array_column(array $array, $column_key[, $index_key = NULL])
205
206 :param array $array: Array to fetch results from
207 :param mixed $column_key: Key of the column to return values from
208 :param mixed $index_key: Key to use for the returned values
209 :returns: An array of values representing a single column from the input array
210 :rtype: array
211
212 For more information, please refer to the `PHP manual for
213 array_column() <http://php.net/array_column>`_.
214
215.. function:: array_replace(array $array1[, ...])
216
217 :param array $array1: Array in which to replace elements
218 :param array ...: Array (or multiple ones) from which to extract elements
219 :returns: Modified array
220 :rtype: array
221
222 For more information, please refer to the `PHP manual for
223 array_replace() <http://php.net/array_replace>`_.
224
225.. function:: array_replace_recursive(array $array1[, ...])
226
227 :param array $array1: Array in which to replace elements
228 :param array ...: Array (or multiple ones) from which to extract elements
229 :returns: Modified array
230 :rtype: array
231
232 For more information, please refer to the `PHP manual for
233 array_replace_recursive() <http://php.net/array_replace_recursive>`_.
234
235 .. important:: Only PHP's native function can detect endless recursion.
236 Unless you are running PHP 5.3+, be careful with references!