note 77732 rejected from function.stream-filter-register by nlopess

From: Date: Tue, 11 Sep 2007 10:49:59 +0000
Subject: note 77732 rejected from function.stream-filter-register by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130363@lists.php.net to get a copy of this message
Note Submitter: gedrox at gmail dot com ---- Could anyone tell why this code returns warning "is not a valid stream resource" after stream_filter_remove function: <?php class strtoupper_filter extends php_user_filter { function filter($in, $out, &$consumed, $closing) { 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 */ $filter = stream_filter_append($fp, "strtoupper"); fwrite($fp, "Line1\n"); fwrite($fp, "Word - 2\n"); /* Remove filter from stream */ echo stream_filter_remove($filter); /* Writing some data without filter */ fwrite($fp, "Easy As 123\n"); fclose($fp); /* Read the contents back out */ readfile("foo-bar.txt"); ?> The only solution I've found so far is to open file once again after removing filter.

« previous php.notes (#130363) next »