note 97516 added to function.stream-wrapper-register
| From: | rogier at osu1 dot php dot net | Date: | Fri, 23 Apr 2010 15:49:40 +0000 |
| Subject: | note 97516 added to function.stream-wrapper-register | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168568@lists.php.net to get a copy of this message | ||
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();
?>
----
Server IP: 64.71.164.2
Probable Submitter: 62.45.2.238
----
Manual Page -- http://www.php.net/manual/en/function.stream-wrapper-register.php
Edit -- https://master.php.net/note/edit/97516
Del: integrated -- https://master.php.net/note/delete/97516/integrated
Del: useless -- https://master.php.net/note/delete/97516/useless
Del: bad code -- https://master.php.net/note/delete/97516/bad+code
Del: spam -- https://master.php.net/note/delete/97516/spam
Del: non-english -- https://master.php.net/note/delete/97516/non-english
Del: in docs -- https://master.php.net/note/delete/97516/in+docs
Del: other reasons-- https://master.php.net/note/delete/97516
Reject -- https://master.php.net/note/reject/97516
Search -- https://master.php.net/manage/user-notes.php