3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Person{ public $name; public $sex; //you require those params public function __construct($name, $sex){ //you set the PROPERTIES, so you can access them later, e.g. in the 'isWoman' function $this->name = $name; $this->sex = $sex; } //here we use those properties public function isWoman(){ if($this->sex === 'woman'){ return true; } return false; } } $p1 = new Person('John', 'man' ); $p2 = new Person('Mary', 'woman' ); var_dump($p1,$p2); if($p2->isWoman()){ echo "p2 is a woman!"; };
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/50bAk
function name:  (null)
number of ops:  19
compiled vars:  !0 = $p1, !1 = $p2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   NEW                                              $2      'Person'
          1        SEND_VAL_EX                                              'John'
          2        SEND_VAL_EX                                              'man'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   24     5        NEW                                              $5      'Person'
          6        SEND_VAL_EX                                              'Mary'
          7        SEND_VAL_EX                                              'woman'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $5
   26    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
   28    14        INIT_METHOD_CALL                                         !1, 'isWoman'
         15        DO_FCALL                                      0  $9      
         16      > JMPZ                                                     $9, ->18
   29    17    >   ECHO                                                     'p2+is+a+woman%21'
   30    18    > > RETURN                                                   1

Class Person:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/50bAk
function name:  __construct
number of ops:  7
compiled vars:  !0 = $name, !1 = $sex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN_OBJ                                               'name'
          3        OP_DATA                                                  !0
   11     4        ASSIGN_OBJ                                               'sex'
          5        OP_DATA                                                  !1
   12     6      > RETURN                                                   null

End of function __construct

Function iswoman:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/50bAk
function name:  isWoman
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   FETCH_OBJ_R                                      ~0      'sex'
          1        IS_IDENTICAL                                             ~0, 'woman'
          2      > JMPZ                                                     ~1, ->4
   17     3    > > RETURN                                                   <true>
   19     4    > > RETURN                                                   <false>
   20     5*     > RETURN                                                   null

End of function iswoman

End of class Person.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.68 ms | 1400 KiB | 15 Q