Passing An Object To mb_convert_variables() Is Deprecated
mb_convert_variables() accepts one or more variables by reference and converts their character encoding in place; historically, an object passed as one of these variables had its accessible public properties converted, just like an array. Until PHP 8.6, this worked silently. In PHP 8.6, passing an object to mb_convert_variables() emits a deprecation notice suggesting get_object_vars() first, even though the conversion still happens exactly as before.
PHP code
<?php
$o = new stdClass();
$o->a = "abc";
$o->b = "def";
$from = mb_convert_variables("UTF-8", "auto", $o);
var_dump($from);
var_dump($o);
?>
Before
string(5) "ASCII"
object(stdClass)#1 (2) {
["a"]=>
string(3) "abc"
["b"]=>
string(3) "def"
}
After
PHP Deprecated: mb_convert_variables(): Passing an object for argument #3 $vars to mb_convert_variables() is deprecated, call get_object_vars() first instead in /codes/mbConvertVariablesObjectDeprecated.php on line 7
Deprecated: mb_convert_variables(): Passing an object for argument #3 $vars to mb_convert_variables() is deprecated, call get_object_vars() first instead in /codes/mbConvertVariablesObjectDeprecated.php on line 7
string(5) "ASCII"
object(stdClass)#1 (2) {
["a"]=>
string(3) "abc"
["b"]=>
string(3) "def"
}
PHP version change
This behavior was deprecated in 8.6.
This behavior changed in .