Re: [SMARTY-DEV] [PATCH] use file_get_contents instead fread($fp, filesize($filename))
| From: | Monte Ohrt | Date: | Tue, 06 Jul 2004 16:36:35 +0000 |
| Subject: | Re: [SMARTY-DEV] [PATCH] use file_get_contents instead fread($fp, filesize($filename)) | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-2441@lists.php.net to get a copy of this message | ||
This has come up before... the problem is that file_get_contents() was introduced in PHP 4.3.0. We can either wait until we consider 4.3.0 to be Smarty's lowest PHP version supported (when that will be?), or build an internal file_get_contents() function in the case it does not exist. I haven't benchmarked the latter, but I'm partial to waiting.
Antony Dovgal wrote:
Hi! Small patch, which removes all fopen() - fread($fp, filesize($filename)) - fclose() cases, replacing them with one file_get_contents() call. Moreover, this fixes problem with bug http://bugs.php.net/29023, which prevents Smarty from working properly. Regardless of the fact that this bug will be fixed (I hope), this fopen-fread-filesize-fclose mess can be safely replaced by one file_get_contents() calls. Please, review it. --- WBR, Antony Dovgal aka tony2001 tony2001@phpclub.net || antony@dovgal.com !DSPAM:40ead217207291919119506! ------------------------------------------------------------------------ Index: Config_File.class.php =================================================================== RCS file: /repository/smarty/libs/Config_File.class.php,v retrieving revision 1.71 diff -u -r1.71 Config_File.class.php --- Config_File.class.php 17 Jun 2004 08:55:09 -0000 1.71 +++ Config_File.class.php 6 Jul 2004 13:50:57 -0000 @@ -234,14 +234,12 @@$config_file = $file_name;ini_set('track_errors', true); - $fp = @fopen($config_file, "r"); - if (!is_resource($fp)) { + if (!is_readable($config_file)) { $this->_trigger_error_msg("Could not open config file '$config_file'"); return false; }- $contents = ($size = filesize($config_file)) ? fread($fp, $size) : ''; - fclose($fp); + $contents = ($size = filesize($config_file)) ? file_get_contents($config_file) : '';$this->_config_data[$config_file] = $this->parse_contents($contents); return true;Index: Smarty.class.php =================================================================== RCS file: /repository/smarty/libs/Smarty.class.php,v retrieving revision 1.492 diff -u -r1.492 Smarty.class.php --- Smarty.class.php 1 Jul 2004 15:48:40 -0000 1.492 +++ Smarty.class.php 6 Jul 2004 13:50:57 -0000 @@ -1705,9 +1705,8 @@*/ function _read_file($filename) { - if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) { - $contents = ($size = filesize($filename)) ? fread($fd, $size) : ''; - fclose($fd); + if ( is_readable($filename) ) { + $contents = ($size = filesize($filename)) ? file_get_contents($filename) : ''; return $contents; } else { return false;