<?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
);
}
- Output for 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
- $dummy:
\Dummy::__set_state(array(
'pub' => 0,
'prot' => 1,
'priv' => 2,
))
$dummy_to_arr:
array (
'pub' => 0,
'' . "\0" . '*' . "\0" . 'prot' => 1,
'' . "\0" . 'Dummy' . "\0" . 'priv' => 2,
)
$dummy_arr_to_obj:
(object) array(
'pub' => 0,
'prot' => 1,
'priv' => 2,
)
$object_vars:
array (
'pub' => 0,
'' . "\0" . '*' . "\0" . 'prot' => 1,
'' . "\0" . 'Dummy' . "\0" . 'priv' => 2,
)
Fatal error: Uncaught Error: Cannot access property starting with "\0" in /in/ScIk3:25
Stack trace:
#0 {main}
thrown in /in/ScIk3 on line 25
Process exited with code 255. - Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.31
- $dummy:
Dummy::__set_state(array(
'pub' => 0,
'prot' => 1,
'priv' => 2,
))
$dummy_to_arr:
array (
'pub' => 0,
'' . "\0" . '*' . "\0" . 'prot' => 1,
'' . "\0" . 'Dummy' . "\0" . 'priv' => 2,
)
$dummy_arr_to_obj:
(object) array(
'pub' => 0,
'prot' => 1,
'priv' => 2,
)
$object_vars:
array (
'pub' => 0,
'' . "\0" . '*' . "\0" . 'prot' => 1,
'' . "\0" . 'Dummy' . "\0" . 'priv' => 2,
)
Fatal error: Uncaught Error: Cannot access property starting with "\0" in /in/ScIk3:25
Stack trace:
#0 {main}
thrown in /in/ScIk3 on line 25
Process exited with code 255.
preferences:
73.98 ms | 408 KiB | 5 Q