3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Serializable { public function store(array $data); public function recover(); } abstract class MyObject implements Serializable { protected $a; protected $data; public function __construct($a = null) { $this->a = $a; } public function __set($index, $value) { // omito comprobaciones.. si la propiedad no existe la creara como public (si recuerdo bien) $this->$index = $value; } public function __get($index) { return $this->$index; } /* * Al implementar el interfaz, tenemos que definir sus metodos * Uso un typehint, indicando que el parametro es array, y dara un Fatal Error en caso contrario */ public function store(array $data) { $this->data = $data; } public function recover() { return $this->data; } public function foo() { echo 'Hello World!'; } } /* * Clase A extiende MyObject que a la vez implementa el interfaz Serializable (se pueden implementar varios interfaces a la vez * y es la unica forma de crear una clase hija que extienda de dos clases padre... algo que de normal no se puede hacer en PHP) */ class A extends MyObject { protected $b; public function __construct($a, $b) { $this->b = $b; parent::__construct($a); } public function foo($a = null) { $str = $a ? $a : $this->a; echo "Hello $str"; } } $a = new A('foo', 'var'); $a->store(array(1, 2, 3)); var_dump($a->recover()); var_dump($a->foo('test')); var_dump($a->foo());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  (null)
number of ops:  28
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'serializable'
    8     1        DECLARE_CLASS                                            'myobject'
   46     2        DECLARE_CLASS                                            'a', 'myobject'
   60     3        NEW                                              $1      'A'
          4        SEND_VAL_EX                                              'foo'
          5        SEND_VAL_EX                                              'var'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $1
   61     8        INIT_METHOD_CALL                                         !0, 'store'
          9        SEND_VAL_EX                                              <array>
         10        DO_FCALL                                      0          
   63    11        INIT_FCALL                                               'var_dump'
         12        INIT_METHOD_CALL                                         !0, 'recover'
         13        DO_FCALL                                      0  $5      
         14        SEND_VAR                                                 $5
         15        DO_ICALL                                                 
   64    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !0, 'foo'
         18        SEND_VAL_EX                                              'test'
         19        DO_FCALL                                      0  $7      
         20        SEND_VAR                                                 $7
         21        DO_ICALL                                                 
   65    22        INIT_FCALL                                               'var_dump'
         23        INIT_METHOD_CALL                                         !0, 'foo'
         24        DO_FCALL                                      0  $9      
         25        SEND_VAR                                                 $9
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Class Serializable:
Function store:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  store
number of ops:  2
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function store

Function recover:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  recover
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   null

End of function recover

End of class Serializable.

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

End of function __construct

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  __set
number of ops:  5
compiled vars:  !0 = $index, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        ASSIGN_OBJ                                               !0
          3        OP_DATA                                                  !1
   19     4      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  __get
number of ops:  4
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        FETCH_OBJ_R                                      ~1      !0
          2      > RETURN                                                   ~1
   23     3*     > RETURN                                                   null

End of function __get

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

End of function store

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

End of function recover

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  foo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   ECHO                                                     'Hello+World%21'
   39     1      > RETURN                                                   null

End of function foo

End of class MyObject.

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  __construct
number of ops:  8
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   50     2        ASSIGN_OBJ                                               'b'
          3        OP_DATA                                                  !1
   51     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   52     7      > RETURN                                                   null

End of function __construct

Function foo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LELCe
function name:  foo
number of ops:  11
compiled vars:  !0 = $a, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV_INIT                                        !0      null
   55     1      > JMPZ                                                     !0, ->4
          2    >   QM_ASSIGN                                        ~2      !0
          3      > JMP                                                      ->6
          4    >   FETCH_OBJ_R                                      ~3      'a'
          5        QM_ASSIGN                                        ~2      ~3
          6    >   ASSIGN                                                   !1, ~2
   56     7        NOP                                                      
          8        FAST_CONCAT                                      ~5      'Hello+', !1
          9        ECHO                                                     ~5
   57    10      > RETURN                                                   null

End of function foo

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.97 ms | 1404 KiB | 15 Q