Re: Found some incompatibilities

messju mohr <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
On Wed, Mar 03, 2004 at 10:39:56AM +0100, Jan Rosier wrote:
> >> On another note: While I looked at _read_file() I noticed that it
> >> provides functionality to read only sub-parts of a file (only $n..$m
> >> lines). But this functionality is never used from withing Smarty. We
> >> could save about 20 lines in core Smarty.class.php if we abandon this
> >> unused feature.
> >
> > Personally, I'd vote to remove those unused lines.
> >
> 
> Me too and when we add the following code. The whole function
> _read_file(...) could be replaced with file_get_contents($file)
> 
> 
> if (!function_exists('file_get_contents')) {
>     /**
>     * Reads entire file into a string
>     * PHP 4 >= 4.3.0
>     *
>     * @param    string  $file
>     *
>     * @return   string
>     */
>     function file_get_contents($file)
>     {
>         if ($filesize = filesize($file) AND $handle = fopen($file, 'r')) {
>             $content = fread($handle, $filesize);
>             fclose($handle);
>             return $content;
>         } else {
>             return '';
>         }
>     }
> }
> 
> 
> Just my 2 euro cents ;-)
> 
> Jan Rosier

I like that approach. We should return boolean false if the fopen
fails, though (as the native file_get_contents() does).

There are just two things that make me feel uncomfortable:

#1 _read_file() locks the file with LOCK_SH before reading. I don't
know if there are any negative side-effects if we replace this by
file_get_contents (which doesn't lock AFAIK).

I don't know of any dependency inside smarty on this shared lock: It
doesn't work Windows anyway and _write_file() works with writing to a
temp-file and an "transactional" rename() command so it doesn't need a
lock. But I'm not 100% sure if the lock is beneficial somewhere.


#2 we should also change fread() in Config_File.class.php to
file_get_contents() if we go for this approach. Config_File is known
to be usable outside of Smarty. If smarty defines it's own
file_get_contents() for older php-versions, than Config_File would
break without Smarty and older php versions.


If these 2 drawbacks are acceptable by Smarty's userbase I'm for
providing a function like the above in Smarty.class.php and let Smarty
move to 4.3.0's file_get_contents().

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.