Re: Found some incompatibilities

boots <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
--- messju mohr <[email protected]> wrote:
> I also thought about file_get_contents and wondered what is better:
> 
> $filesize = filesize($filename);
> $contents = ($filesize > 0) ? fread($fd, $filesize) : '';
> 
> or something along:
> 
> if (function_exists('file_get_contents'))
>     $contents = file_get_contents($filename);
> else
>     $contents = fread($fd, filesize($filename));
>
> I have no strong preference for the one or the other. Overall I think
> it is correct for php to issue a warning if it is requested to read
> zero bytes.

Agreed, which indicates that it was either sloppy to request 0 bytes in
the first place or more likely just a convenience considering the
historical behaviour of fread. Since file_get_contents obviates the
need to do a filesize, it maintains a small advantadge to me.

In hindsight, littering the codebase with more version switches may not
lend itself to long-term maintainability. It would also be possible to
abstract platform specific features to a file which contained a wrapper
function which Smarty would use. This may not be the appropriate
example to justify such a decision, but I'm just thinking out loud :)

> 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.

cheers,
xo boots

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

-- 
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.