3v4l.org

run code in 300+ PHP versions simultaneously
<?php // This is a basic class without any special behavior. No deprecation error occur despite the public_property being unset. $foo = new Foo(); $foo->public_property = true; unset( $foo->public_property ); $foo->public_property = true; // A class with a __set magic method that allows modifying declared public properties, mimicking the basic class behaviour and providing more backward compatibility. $baz = new Baz(); $baz->public_property = true; unset( $baz->public_property ); $baz->public_property = true; // This is a class with a __set magic method that restricts dynamic property creation. $bar = new Bar(); $bar->public_property = true; unset( $bar->public_property ); $bar->public_property = true; class Foo { public $public_property; } class Baz { public $public_property; public function __set( $prop, $value ) { if ( 'known_dynamic_property' === $prop ) { // Dynamic property-specific logic goes here. return; } // Checks if the property is a known public property and allows setting it. if ( 'public_property' === $prop ) { $this->public_property = $value; return; } trigger_error( sprintf( 'Setting the dynamic property "%s" on %s is deprecated', $prop, __CLASS__ ), E_USER_DEPRECATED ); } } class Bar { public $public_property; public function __set( $prop, $value ) { if ( 'known_dynamic_property' === $prop ) { // Dynamic property-specific logic goes here. return; } trigger_error( sprintf( 'Setting the dynamic property "%s" on %s is deprecated', $prop, __CLASS__ ), E_USER_DEPRECATED ); } }
Output for git.master_jit, git.master, rfc.property-hooks
Deprecated: Setting the dynamic property "public_property" on Bar is deprecated in /in/QU0tT on line 57

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:
50.02 ms | 405 KiB | 5 Q