note 97516 deleted from function.stream-wrapper-register by danbrown
| From: | danbrown@php.net | Date: | Fri, 23 Apr 2010 17:01:35 +0000 |
| Subject: | note 97516 deleted from function.stream-wrapper-register by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168569@lists.php.net to get a copy of this message | ||
Note Submitter: rogier
----
As mentioned, some PHP versions have bugs related to the correct interpretation of the return value
of stream_eof.
"none at your dot biz" already proposed a correction based on
a version compare, but I always long for somewhat more generic methods, so I came up with the
following to test for this incorrectness, setting a constant boolean indicating an
end-of-data definition.
In your user defined stream wrapper, you could then return a value based on this flag as follows:
<?php
...
function stream_eol()
{
$eol = false;
// perform code to set the real $eol.
//....
// return based on definition
return ( $eol ? TS_EOLDEF : !TSEOLDEF );
}
...
?>
Now here's the code for the very simple detection mechanism:
<?php
final class StreamEolDetect
{
public function stream_open($path, $mode, $options, &$opened_path)
{
return true;
}
public function stream_close()
{
}
public function stream_eof()
{
return false;
}
static final public function PerformDetect()
{
if (defined('TS_EOLDEF'))
return;
$wname = md5('StreamEolDetect'.time());
stream_wrapper_register($wname, __CLASS__);
$fh=fopen($wname.'://dummy','r');
define('TS_EOLDEF', !feof($fh));
fclose($fh);
}
}
StreamEolDetect::PerformDetect();
?>