3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait setData { static function setData( $data ) { DataCollector::collectedData( 'set', $data ); } } trait dataHandler { use setData; private static function getCollectedData() { return DataCollector::collectedData( 'get' ); } private static function collectedData( $type, $value = NULL ) { if( strtolower( $type ) === 'set' ) { DataCollector::$CollectionData[] = $value; var_dump( DataCollector::$CollectionData ); } elseif( strtolower( $type ) === 'get' ) return DataCollector::$CollectionData; } } class DataCollector { use dataHandler { getCollectedData as public; collectedData as public; } private static $CollectionData = array(); } class Field { use setData {} } class TextField extends Field { public function __construct( $type, $text = NULL ) { $this->setData( $type ); } } /* class A { use setData{} public function __construct( $type, $text = NULL ) { $this->setData( $type ); } } */ $Field1 = new TextField( '1' ); $Field2 = new TextField( '2' ); #$A = new A( '3' ); #DataCollector::setData('4'); #dataHandler::setData('5'); var_dump( DataCollector::getCollectedData() );
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/tSdu4
function name:  (null)
number of ops:  26
compiled vars:  !0 = $Field1, !1 = $Field2
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   NOP                                                      
   8     1        DECLARE_CLASS                                    $3      '%00datahandler%2Fin%2FtSdu40x7fa8a4fc1255', 'datahandler'
   9     2        ADD_TRAIT                                                $3, 'setData'
   8     3        BIND_TRAITS                                              $3
  25     4        DECLARE_CLASS                                    $4      '%00datacollector%2Fin%2FtSdu40x7fa8a4fc12e9', 'datacollector'
  26     5        ADD_TRAIT                                                $4, 'dataHandler'
  25     6        BIND_TRAITS                                              $4
  30     7        DECLARE_CLASS                                    $5      '%00field%2Fin%2FtSdu40x7fa8a4fc1309', 'field'
         8        ADD_TRAIT                                                $5, 'setData'
         9        BIND_TRAITS                                              $5
  32    10        FETCH_CLASS                                   0  :6      'Field'
        11        DECLARE_INHERITED_CLASS                          $7      '%00textfield%2Fin%2FtSdu40x7fa8a4fc138c', 'textfield'
  46    12        NEW                                              $8      :10
        13        SEND_VAL_EX                                              '1'
        14        DO_FCALL                                      0          
        15        ASSIGN                                                   !0, $8
  47    16        NEW                                              $11     :13
        17        SEND_VAL_EX                                              '2'
        18        DO_FCALL                                      0          
        19        ASSIGN                                                   !1, $11
  52    20        INIT_FCALL                                               'var_dump'
        21        INIT_STATIC_METHOD_CALL                                  'DataCollector', 'getCollectedData'
        22        DO_FCALL                                      0  $14     
        23        SEND_VAR                                                 $14
        24        DO_ICALL                                                 
        25      > RETURN                                                   1

Class setData:
Function setdata:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/tSdu4
function name:  setData
number of ops:  6
compiled vars:  !0 = $data
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   RECV                                             !0      
   4     1        INIT_STATIC_METHOD_CALL                                  'DataCollector', 'collectedData'
         2        SEND_VAL_EX                                              'set'
         3        SEND_VAR_EX                                              !0
         4        DO_FCALL                                      0          
   5     5      > RETURN                                                   null

End of function setdata

End of class setData.

Class dataHandler:
Function getcollecteddata:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/tSdu4
function name:  getCollectedData
number of ops:  5
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  12     0  E >   INIT_STATIC_METHOD_CALL                                  'DataCollector', 'collectedData'
         1        SEND_VAL_EX                                              'get'
         2        DO_FCALL                                      0  $0      
         3      > RETURN                                                   $0
  13     4*     > RETURN                                                   null

End of function getcollecteddata

Function collecteddata:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
Jump found. Position 1 = 22
Branch analysis from position: 22
Jump found. Position 1 = -2
Branch analysis from position: 15
Jump found. Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
Jump found. Position 1 = -2
Branch analysis from position: 22
filename:       /in/tSdu4
function name:  collectedData
number of ops:  23
compiled vars:  !0 = $type, !1 = $value
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  15     0  E >   RECV                                             !0      
         1        RECV_INIT                                        !1      null
  16     2        INIT_FCALL                                               'strtolower'
         3        SEND_VAR                                                 !0
         4        DO_ICALL                                         $2      
         5        IS_IDENTICAL                                     ~3      $2, 'set'
         6      > JMPZ                                                     ~3, ->15
  17     7    >   FETCH_W                      static member       $4      'CollectionData'
         8        ASSIGN_DIM                                               $4
         9        OP_DATA                                                  !1
  18    10        INIT_FCALL                                               'var_dump'
        11        FETCH_R                      static member       $6      'CollectionData'
        12        SEND_VAR                                                 $6
        13        DO_ICALL                                                 
        14      > JMP                                                      ->22
  20    15    >   INIT_FCALL                                               'strtolower'
        16        SEND_VAR                                                 !0
        17        DO_ICALL                                         $8      
        18        IS_IDENTICAL                                     ~9      $8, 'get'
        19      > JMPZ                                                     ~9, ->22
  21    20    >   FETCH_R                      static member       $10     'CollectionData'
        21      > RETURN                                                   $10
  22    22    > > RETURN                                                   null

End of function collecteddata

End of class dataHandler.

Class DataCollector: [no user functions]
Class Field: [no user functions]
Class TextField:
Function __construct:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/tSdu4
function name:  __construct
number of ops:  6
compiled vars:  !0 = $type, !1 = $text
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  33     0  E >   RECV                                             !0      
         1        RECV_INIT                                        !1      null
  34     2        INIT_METHOD_CALL                                         'setData'
         3        SEND_VAR_EX                                              !0
         4        DO_FCALL                                      0          
  35     5      > RETURN                                                   null

End of function __construct

End of class TextField.

Generated using Vulcan Logic Dumper, using php 7.2.0