<?php
define( 'APPLY_PATCH', false );
define( 'VERBOSE', true );
class Dummy {
public $pub = 0;
protected $prot = 1;
private $priv = 2;
}
$dummy = new Dummy();
$dummy_to_arr = (array) $dummy; // Doing this adds NUL bytes to private and protected property keys.
$dummy_arr_to_obj = (object) $dummy_to_arr; // Now there's NUL bytes in the property names.
$object_vars = APPLY_PATCH ? wp_get_object_vars( $dummy_arr_to_obj ) : get_object_vars( $dummy_arr_to_obj );
if ( VERBOSE ) {
echo '$dummy: ', PHP_EOL, var_export( $dummy, true ), PHP_EOL, PHP_EOL;
echo '$dummy_to_arr: ', PHP_EOL, var_export( $dummy_to_arr, true ), PHP_EOL, PHP_EOL;
echo '$dummy_arr_to_obj: ', PHP_EOL, var_export( $dummy_arr_to_obj, true ), PHP_EOL, PHP_EOL;
echo '$object_vars: ', PHP_EOL, var_export( $object_vars, true ), PHP_EOL, PHP_EOL;
}
foreach ( $object_vars as $property_name => $property_value ) {
$dummy_arr_to_obj->$property_name = '1';
}
// The new function in PR 3607.
function wp_get_object_vars( $obj ) {
return array_filter(
get_object_vars( $obj ),
function ( $key ) {
return ord( $key ) !== 0;
},
ARRAY_FILTER_USE_KEY
);
}
preferences:
23.65 ms | 408 KiB | 5 Q