3v4l.org

run code in 300+ PHP versions simultaneously
<?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 git.master_jit, git.master, rfc.property-hooks
$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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
42.84 ms | 406 KiB | 5 Q