#46171 [NEW]: stream_bucket_new don't work with write streams
From: Keisial at gmail dot com
Operating system:
PHP version: 5.3CVS-2008-09-25 (snap)
PHP Bug Type: Streams related
Bug description: stream_bucket_new don't work with write streams
Description:
------------
Calling stream_bucket_new on a write stream doesn't work (the same code
fopening for reading works).
Reproduce code:
---------------
<?php /** Adapted from
http://php.net/manual/function.stream-filter-register.php
**/
/* Define our filter class */
class strtoupper_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing)
{
$new_bucket = stream_bucket_new($this->stream, "Uppercase text: ");
if ($new_bucket === false) throw new Exception("stream_bucket_new
should have returned a bucket");
stream_bucket_append($out, $new_bucket);
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
/* Register our filter with PHP */
stream_filter_register("strtoupper", "strtoupper_filter")
or die("Failed to register filter");
$fp = fopen("foo-bar.txt", "w");
/* Attach the registered filter to the stream just opened */
stream_filter_append($fp, "strtoupper");
fwrite($fp, "Line1\n");
fwrite($fp, "Word - 2\n");
fwrite($fp, "Easy As 123\n");
fclose($fp);
// Read the contents back out
readfile("foo-bar.txt");
?>
Actual result:
--------------
Warning: stream_bucket_new(): 5 is not a valid stream resource in
bucket_new_testcase.php on line 7
Fatal error: Uncaught exception 'Exception' with message
'stream_bucket_new should have returned a bucket'
Stack trace:
#0 [internal function]: strtoupper_filter->filter(Resource id #20,
Resource id #21, 0, true)
#1 bucket_new_testcase.php(36): fclose(Resource id #5)
#2 {main}
thrown in bucket_new_testcase.php on line 8
--
Edit bug report at http://bugs.php.net/?id=46171&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46171&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46171&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46171&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46171&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=46171&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46171&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46171&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46171&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46171&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46171&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46171&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46171&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46171&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46171&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46171&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46171&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46171&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46171&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46171&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46171&r=mysqlcfg
Thread (2 messages)
- Keisial at gmail dot com