3v4l.org

run code in 500+ 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:  45
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        FRAMELESS_ICALL_3                str_replace         ~10     '10%3A%22WithPublic%22', '11%3A%22WithPrivate%22'
         10        OP_DATA                                                      !1
         11        SEND_VAL                                                     ~10
   24    12        DO_ICALL                                             $11     
         13        ASSIGN                                                       !2, $11
   27    14        INIT_FCALL                                                   'var_dump'
         15        SEND_VAR                                                     !2
         16        DO_ICALL                                                     
   35    17        INIT_FCALL                                                   'var_export'
         18        INIT_METHOD_CALL                                             !2, 'getProperty'
         19        DO_FCALL                                          0  $14     
         20        SEND_VAR                                                     $14
         21        DO_ICALL                                                     
   46    22        NEW                                                  $16     'WithPrivate'
         23        SEND_VAL_EX                                                  'value'
         24        DO_FCALL                                          0          
         25        ASSIGN                                                       !3, $16
   47    26        INIT_FCALL                                                   'serialize'
         27        SEND_VAR                                                     !3
         28        DO_ICALL                                             $19     
         29        ASSIGN                                                       !1, $19
   49    30        INIT_FCALL                                                   'unserialize'
   50    31        FRAMELESS_ICALL_3                str_replace         ~21     '11%3A%22WithPrivate%22', '10%3A%22WithPublic%22'
         32        OP_DATA                                                      !1
         33        SEND_VAL                                                     ~21
   49    34        DO_ICALL                                             $22     
         35        ASSIGN                                                       !4, $22
   52    36        INIT_FCALL                                                   'var_dump'
         37        SEND_VAR                                                     !4
         38        DO_ICALL                                                     
   60    39        INIT_FCALL                                                   'var_export'
         40        INIT_METHOD_CALL                                             !4, 'getProperty'
         41        DO_FCALL                                          0  $25     
         42        SEND_VAR                                                     $25
         43        DO_ICALL                                                     
   62    44      > 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.5.0


preferences:
161.55 ms | 2284 KiB | 17 Q