3v4l.org

run code in 300+ PHP versions simultaneously
<?php # Given two classes with the same property name but different visibility class WithPublic { public $property; function __construct( $p ) { $this->property = $p; } function getProperty() { return $this->property; } } class WithPrivate { private $property; function __construct( $p ) { $this->property = $p; } function getProperty() { return $this->property; } } $priv = new WithPrivate( 'value' ); $cache = serialize( $priv ); $mut_priv_to_pub = unserialize( str_replace( '11:"WithPrivate"', '10:"WithPublic"', $cache) ); var_dump( $mut_priv_to_pub ); # class WithPublic#4 (2) { # public $property => # NULL # private $property => # string(5) "value" # } var_export( $mut_priv_to_pub->getProperty() ); # On Zend PHP: NULL # On HHVM 3.15.4, 3.17.1: 'value'
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Deprecated: Creation of dynamic property WithPublic::$property is deprecated in /in/jrmrO on line 18 object(WithPublic)#2 (2) { ["property"]=> NULL ["property":"WithPrivate":private]=> string(5) "value" } NULL
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.8 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
object(WithPublic)#2 (2) { ["property"]=> NULL ["property":"WithPrivate":private]=> string(5) "value" } NULL
Output for 7.2.0 - 7.2.6
object(WithPublic)#2 (1) { ["property"]=> string(5) "value" } 'value'

preferences:
151.76 ms | 401 KiB | 168 Q