stream_bucket_prepend()
stream_bucket_prepend() — Prepend bucket to brigade.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function can be called to prepend a bucket to a bucket brigade. It is typically called from php_user_filter::filter().
Signature
stream_bucket_prepend(resource $brigade, StreamBucket $bucket): void
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $brigade | resource | brigade is a resource pointing to a bucket brigade which contains one or more bucket objects. |
| $bucket | StreamBucket | A bucket object. |
Return value
No value is returned.
Example
A runnable snippet:
class foo extends php_user_filter { protected $calls = 0; public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $consumed += $bucket->datalen; if ($this->calls++ == 2) { // This bucket will appear again before any other bucket. stream_bucket_prepend($in, $bucket); } } return PSFS_FEED_ME; } } stream_filter_register('test', 'foo'); print file_get_contents('php://filter/read=test/resource=foo');
Changelog
| Version | Change |
|---|---|
| 8.4.0 | bucket expects a StreamBucket instance now; previously, an stdClass was expected. |
All PHP 8.5 built-in functions
Reference card built from the PHP manual page stream_bucket_prepend() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.