Passing An Object As Filter Options To zlib/bzip2 Functions Is Deprecated
deflate_init(), inflate_init(), and the zlib.deflate/bzip2.compress stream filters accept an options value that PHP reads as an array. Until PHP 8.6, an object was silently accepted and read the same way as an array. In PHP 8.6, passing an object emits a deprecation notice recommending get_object_vars() first; the object’s properties are still read the same way as before.
PHP code
<?php
class Options {
public $level = 6;
}
$context = deflate_init(ZLIB_ENCODING_RAW, new Options());
var_dump($context !== false);
?>
Before
bool(true)
After
PHP Deprecated: deflate_init(): Passing an object for argument #2 $option to deflate_init() is deprecated, call get_object_vars() first instead in /codes/zlibBzip2ObjectOptionsDeprecated86.php on line 7
Deprecated: deflate_init(): Passing an object for argument #2 $option to deflate_init() is deprecated, call get_object_vars() first instead in /codes/zlibBzip2ObjectOptionsDeprecated86.php on line 7
bool(true)
PHP version change
This behavior was deprecated in 8.6.
This behavior changed in .
See Also
Error Messages
- deflate_init(): Passing an object for argument #2 $option to deflate_init() is deprecated, call get_object_vars() first instead
- inflate_init(): Passing an object for argument #2 $option to inflate_init() is deprecated, call get_object_vars() first instead
- stream_filter_append(): Passing an object for filter parameters for zlib.deflate is deprecated, call get_object_vars() first instead
- stream_filter_append(): Passing an object for filter parameters for bzip2.compress is deprecated, call get_object_vars() first instead