3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait Foo { private $traitProperty = 'blah'; public function getTraitProperty() { return $this->traitProperty; } public function getClassPropertyFromTrait() { return $this->classProperty; } } class MyClass { use Foo; private $classProperty = 'meh'; public function getTraitPropertyFromClass() { return $this->traitProperty; } public function getClassProperty() { return $this->classProperty; } } $x = new MyClass(); var_dump($x->getTraitProperty()); var_dump($x->getTraitPropertyFromClass()); var_dump($x->getClassProperty()); var_dump($x->getClassPropertyFromTrait());
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/M80Zl
function name:  (null)
number of ops:  28
compiled vars:  !0 = $x
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   NOP                                                      
  19     1        DECLARE_CLASS                                    $2      '%00myclass%2Fin%2FM80Zl0x7f4a93252208', 'myclass'
  21     2        ADD_TRAIT                                                $2, 'Foo'
  19     3        BIND_TRAITS                                              $2
  36     4        NEW                                              $3      :-2
         5        DO_FCALL                                      0          
         6        ASSIGN                                                   !0, $3
  37     7        INIT_FCALL                                               'var_dump'
         8        INIT_METHOD_CALL                                         !0, 'getTraitProperty'
         9        DO_FCALL                                      0  $6      
        10        SEND_VAR                                                 $6
        11        DO_ICALL                                                 
  38    12        INIT_FCALL                                               'var_dump'
        13        INIT_METHOD_CALL                                         !0, 'getTraitPropertyFromClass'
        14        DO_FCALL                                      0  $8      
        15        SEND_VAR                                                 $8
        16        DO_ICALL                                                 
  39    17        INIT_FCALL                                               'var_dump'
        18        INIT_METHOD_CALL                                         !0, 'getClassProperty'
        19        DO_FCALL                                      0  $10     
        20        SEND_VAR                                                 $10
        21        DO_ICALL                                                 
  40    22        INIT_FCALL                                               'var_dump'
        23        INIT_METHOD_CALL                                         !0, 'getClassPropertyFromTrait'
        24        DO_FCALL                                      0  $12     
        25        SEND_VAR                                                 $12
        26        DO_ICALL                                                 
        27      > RETURN                                                   1

Class Foo:
Function gettraitproperty:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/M80Zl
function name:  getTraitProperty
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  10     0  E >   FETCH_OBJ_R                                      $0      'traitProperty'
         1      > RETURN                                                   $0
  11     2*     > RETURN                                                   null

End of function gettraitproperty

Function getclasspropertyfromtrait:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/M80Zl
function name:  getClassPropertyFromTrait
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  15     0  E >   FETCH_OBJ_R                                      $0      'classProperty'
         1      > RETURN                                                   $0
  16     2*     > RETURN                                                   null

End of function getclasspropertyfromtrait

End of class Foo.

Class MyClass:
Function gettraitpropertyfromclass:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/M80Zl
function name:  getTraitPropertyFromClass
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  27     0  E >   FETCH_OBJ_R                                      $0      'traitProperty'
         1      > RETURN                                                   $0
  28     2*     > RETURN                                                   null

End of function gettraitpropertyfromclass

Function getclassproperty:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/M80Zl
function name:  getClassProperty
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  32     0  E >   FETCH_OBJ_R                                      $0      'classProperty'
         1      > RETURN                                                   $0
  33     2*     > RETURN                                                   null

End of function getclassproperty

End of class MyClass.

Generated using Vulcan Logic Dumper, using php 7.1.0