3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Singleton { # Holds Parent Instance private static $_instance; # Holds Reference To zVal protected $_args; # Create The Instance protected function __construct() {} # Static Call To Get Instance public static function getInstance() { return self::$_instance ?? (self::$_instance = new self()); } # Bind zVal Of Passed Reference To Index protected function _bindParam(&$val) { $this->_arg = &$val; return $this; } } abstract class Model { abstract public function save(); # Set your DB up here } class MyModel extends Model { use \Singleton { _bindParam as public bindParam; } public function save() { print_r($this->_arg); } } MyModel::getInstance()->bindParam($row); foreach([['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I']] as $key => $row) { $row[0] = 'Changed'; MyModel::getInstance()->save(); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/ePbei
function name:  (null)
number of ops:  18
compiled vars:  !0 = $row, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   DECLARE_CLASS                                            'mymodel', 'model'
   44     1        INIT_STATIC_METHOD_CALL                                  'MyModel', 'getInstance'
          2        DO_FCALL                                      0  $2      
          3        INIT_METHOD_CALL                                         $2, 'bindParam'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
   46     6      > FE_RESET_R                                       $4      <array>, ->16
          7    > > FE_FETCH_R                                       ~5      $4, !0, ->16
          8    >   ASSIGN                                                   !1, ~5
   47     9        ASSIGN_DIM                                               !0, 0
         10        OP_DATA                                                  'Changed'
   48    11        INIT_STATIC_METHOD_CALL                                  'MyModel', 'getInstance'
         12        DO_FCALL                                      0  $8      
         13        INIT_METHOD_CALL                                         $8, 'save'
         14        DO_FCALL                                      0          
   46    15      > JMP                                                      ->7
         16    >   FE_FREE                                                  $4
   49    17      > RETURN                                                   1

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

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ePbei
function name:  getInstance
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   FETCH_STATIC_PROP_IS                             ~0      '_instance'
          1        COALESCE                                         ~1      ~0
          2        NEW                          self                $3      
          3        DO_FCALL                                      0          
          4        ASSIGN_STATIC_PROP                               ~2      '_instance'
          5        OP_DATA                                                  $3
          6        QM_ASSIGN                                        ~1      ~2
          7      > RETURN                                                   ~1
   17     8*     > RETURN                                                   null

End of function getinstance

Function _bindparam:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ePbei
function name:  _bindParam
number of ops:  6
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        ASSIGN_OBJ_REF                                           '_arg'
          2        OP_DATA                                                  !0
   22     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   23     5*     > RETURN                                                   null

End of function _bindparam

End of class Singleton.

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

End of function save

End of class Model.

Class MyModel:
Function save:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ePbei
function name:  save
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_FCALL                                               'print_r'
          1        FETCH_OBJ_R                                      ~0      '_arg'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                                 
   41     4      > RETURN                                                   null

End of function save

End of class MyModel.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.74 ms | 1007 KiB | 14 Q