Skip to content

Commit 0f0b769

Browse files
committed
Deprecated do_hash() and read_file() in favor of hash() and file_get_contents() respectively
1 parent c839d28 commit 0f0b769

File tree

8 files changed

+29
-43
lines changed

8 files changed

+29
-43
lines changed

system/database/DB_cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function read($sql)
9999
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
100100
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
101101

102-
if (FALSE === ($cachedata = read_file($filepath)))
102+
if (FALSE === ($cachedata = file_get_contents($filepath)))
103103
{
104104
return FALSE;
105105
}

system/helpers/file_helper.php

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,15 @@
4444
*
4545
* Opens the file specfied in the path and returns it as a string.
4646
*
47+
* This function is DEPRECATED and should be removed in
48+
* CodeIgniter 3.1+. Use file_get_contents() instead.
49+
*
4750
* @param string path to file
4851
* @return string
4952
*/
5053
function read_file($file)
5154
{
52-
if ( ! file_exists($file))
53-
{
54-
return FALSE;
55-
}
56-
57-
if (function_exists('file_get_contents'))
58-
{
59-
return file_get_contents($file);
60-
}
61-
62-
if ( ! $fp = @fopen($file, FOPEN_READ))
63-
{
64-
return FALSE;
65-
}
66-
67-
flock($fp, LOCK_SH);
68-
69-
$data = '';
70-
if (filesize($file) > 0)
71-
{
72-
$data =& fread($fp, filesize($file));
73-
}
74-
75-
flock($fp, LOCK_UN);
76-
fclose($fp);
77-
78-
return $data;
55+
return file_get_contents($file);
7956
}
8057
}
8158

system/helpers/security_helper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ function sanitize_filename($filename)
7777
/**
7878
* Hash encode a string
7979
*
80+
* This function is DEPRECATED and should be removed in
81+
* CodeIgniter 3.1+. Use hash() instead.
82+
*
8083
* @param string
8184
* @param string
8285
* @return string

system/libraries/Cache/drivers/Cache_file.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function get($id)
7171
return FALSE;
7272
}
7373

74-
$data = unserialize(read_file($this->_cache_path.$id));
74+
$data = unserialize(file_get_contents($this->_cache_path.$id));
7575

7676
if (time() > $data['time'] + $data['ttl'])
7777
{
@@ -165,7 +165,7 @@ public function get_metadata($id)
165165
return FALSE;
166166
}
167167

168-
$data = unserialize(read_file($this->_cache_path.$id));
168+
$data = unserialize(file_get_contents($this->_cache_path.$id));
169169

170170
if (is_array($data))
171171
{

user_guide_src/source/changelog.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ Release Date: Not Released
4444

4545
- Helpers
4646

47-
- create_captcha() accepts additional colors parameter, allowing for color customization
48-
- url_title() will now trim extra dashes from beginning and end.
47+
- ``create_captcha()`` accepts additional colors parameter, allowing for color customization.
48+
- ``url_title()`` will now trim extra dashes from beginning and end.
4949
- Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`.
50-
- Changed humanize() to include a second param for the separator.
50+
- Changed ``humanize()`` to include a second param for the separator.
5151
- Refactored ``plural()`` and ``singular()`` to avoid double pluralization and support more words.
5252
- Added an optional third parameter to ``force_download()`` that enables/disables sending the actual file MIME type in the Content-Type header (disabled by default).
5353
- Added an optional third parameter to ``timespan()`` that constrains the number of time units displayed.
54-
- Added a work-around in force_download() for a bug Android <= 2.1, where the filename extension needs to be in uppercase.
55-
- form_dropdown() will now also take an array for unity with other form helpers.
56-
- set_realpath() can now also handle file paths as opposed to just directories.
57-
- do_hash() now uses PHP's native hash() function, supporting more algorithms.
58-
- Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
59-
- Removed deprecated helper function ``js_insert_smiley()`` from smiley helper.
54+
- Added a work-around in ``force_download()`` for a bug Android <= 2.1, where the filename extension needs to be in uppercase.
55+
- ``form_dropdown()`` will now also take an array for unity with other form helpers.
56+
- ``do_hash()`` now uses PHP's native ``hash()`` function (supporting more algorithms) and is deprecated.
57+
- Removed previously deprecated helper function ``js_insert_smiley()`` from smiley helper.
58+
- :doc:`File Helper <helpers/file_helper>` changes include:
59+
- ``set_realpath()`` can now also handle file paths as opposed to just directories.
60+
- Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
61+
- ``read_file()`` is now a deprecated alias of ``file_get_contents()``.
6062

6163
- Database
6264

user_guide_src/source/helpers/file_helper.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ The path can be a relative or full server path. Returns FALSE (boolean) on failu
3232
controller or view files. CodeIgniter uses a front controller so paths
3333
are always relative to the main site index.
3434

35+
.. note:: This function is DEPRECATED. Use the native ``file_get_contents()``
36+
instead.
37+
3538
If your server is running an `open_basedir` restriction this function might not work if you are trying to access a file above the calling script.
3639

3740
write_file('path', $data)

user_guide_src/source/helpers/security_helper.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ for a full list of supported algorithms.
4343
$str = do_hash($str); // SHA1
4444
$str = do_hash($str, 'md5'); // MD5
4545

46-
.. note:: This function was formerly named dohash(), which has been
47-
removed in favor of `do_hash()`.
46+
.. note:: This function was formerly named ``dohash()``, which has been
47+
removed in favor of ``do_hash()``.
48+
49+
.. note:: This function is DEPRECATED. Use the native ``hash()`` instead.
4850

4951
strip_image_tags()
5052
==================

user_guide_src/source/helpers/string_helper.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
3636
- **unique**: Encrypted with MD5 and uniqid(). Note: The length
3737
parameter is not available for this type. Returns a fixed length 32
3838
character string.
39-
- **sha1**: An encrypted random number based on do_hash() from the
40-
:doc:`security helper <security_helper>`.
39+
- **sha1**: An encrypted random number based on ``sha1()``.
4140

4241
Usage example
4342

0 commit comments

Comments
 (0)