Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

Extension

© 2023-2026, Damien Seguy - Exakat