3v4l.org

run code in 300+ PHP versions simultaneously
<?php # Acknowledging Stas Malyshev # https://phabricator.wikimedia.org/T156364#2977719 # Given two classes with the same property name but different visibility class WithPublic { public $property; function __construct( $p ) { $this->property = $p; } function getProperty() { print $this->property; } } class WithPrivate { private $property; function __construct( $p ) { $this->property = $p; } function getProperty() { print $this->property; } } $pub = new WithPublic( 'value' ); # Lets pretend it is held in a permanent cache: $cache = serialize( $pub ); # Later on NEW code is deployed which change the property signature to private. # Simulate the class changed: $mut_pub_to_priv = unserialize( str_replace( '10:"WithPublic"', '11:"WithPrivate"', $cache ) ); var_dump( $mut_pub_to_priv ); # class WithPrivate#2 (2) { # private $property => # NULL # public $property => # string(5) "value" # } var_export( $mut_pub_to_priv->getProperty() ); # NULL # The object restored from cache is not quite the one we expected and cause # some havoc ( https://phabricator.wikimedia.org/T156364 ). Then Zend and HHVM # consistently yield "NULL". # The other way around. Cache with private property restore to class with # public 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: valueNULL
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZk8B
function name:  (null)
number of ops:  51
compiled vars:  !0 = $pub, !1 = $cache, !2 = $mut_pub_to_priv, !3 = $priv, !4 = $mut_priv_to_pub
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $5      'WithPublic'
          1        SEND_VAL_EX                                              'value'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   20     4        INIT_FCALL                                               'serialize'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !1, $8
   24     8        INIT_FCALL                                               'unserialize'
   25     9        INIT_FCALL                                               'str_replace'
         10        SEND_VAL                                                 '10%3A%22WithPublic%22'
         11        SEND_VAL                                                 '11%3A%22WithPrivate%22'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $10     
         14        SEND_VAR                                                 $10
         15        DO_ICALL                                         $11     
   24    16        ASSIGN                                                   !2, $11
   27    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                                 
   35    20        INIT_FCALL                                               'var_export'
         21        INIT_METHOD_CALL                                         !2, 'getProperty'
         22        DO_FCALL                                      0  $14     
         23        SEND_VAR                                                 $14
         24        DO_ICALL                                                 
   46    25        NEW                                              $16     'WithPrivate'
         26        SEND_VAL_EX                                              'value'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !3, $16
   47    29        INIT_FCALL                                               'serialize'
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $19     
         32        ASSIGN                                                   !1, $19
   49    33        INIT_FCALL                                               'unserialize'
   50    34        INIT_FCALL                                               'str_replace'
         35        SEND_VAL                                                 '11%3A%22WithPrivate%22'
         36        SEND_VAL                                                 '10%3A%22WithPublic%22'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                         $21     
         39        SEND_VAR                                                 $21
         40        DO_ICALL                                         $22     
   49    41        ASSIGN                                                   !4, $22
   52    42        INIT_FCALL                                               'var_dump'
         43        SEND_VAR                                                 !4
         44        DO_ICALL                                                 
   60    45        INIT_FCALL                                               'var_export'
         46        INIT_METHOD_CALL                                         !4, 'getProperty'
         47        DO_FCALL                                      0  $25     
         48        SEND_VAR                                                 $25
         49        DO_ICALL                                                 
   62    50      > RETURN                                                   1

Class WithPublic:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZk8B
function name:  __construct
number of ops:  4
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'property'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function __construct

Function getproperty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZk8B
function name:  getProperty
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                      ~0      'property'
          1        ECHO                                                     ~0
          2      > RETURN                                                   null

End of function getproperty

End of class WithPublic.

Class WithPrivate:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZk8B
function name:  __construct
number of ops:  4
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'property'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function __construct

Function getproperty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZk8B
function name:  getProperty
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~0      'property'
          1        ECHO                                                     ~0
          2      > RETURN                                                   null

End of function getproperty

End of class WithPrivate.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.79 ms | 1405 KiB | 23 Q