3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Entity { private $name; public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; return $this; } } class DB { public function findByName($name) { if ($name === 'belette') { return new Entity($name); } return false; } } class Test { private $db; public function __construct(DB $db) { $this->db = $db; } public function getEntity($name): Entity { $entity = $this->db->findByName($name); $new = false; if (false === $entity) { $entity = new Entity(); $entity->setName($name); $this->db->insert($entity); $new = true; } return new class($entity, $new) { private $new; public $entity; public function __construct(Entity $entity, $new) { $this->entity = $entity; $this->new = $new; } public function isNew() { return $this->new; } }; } } $db = new DB(); $test = new Test($db); $result = $test->getEntity('belette'); if ($result->isNew()) { echo "L'entité 'belette' n'existait pas en base\n"; } var_dump($result->entity);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/90o61
function name:  (null)
number of ops:  20
compiled vars:  !0 = $db, !1 = $test, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   NEW                                              $3      'DB'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   69     3        NEW                                              $6      'Test'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $6
   70     7        INIT_METHOD_CALL                                         !1, 'getEntity'
          8        SEND_VAL_EX                                              'belette'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !2, $9
   71    11        INIT_METHOD_CALL                                         !2, 'isNew'
         12        DO_FCALL                                      0  $11     
         13      > JMPZ                                                     $11, ->15
   72    14    >   ECHO                                                     'L%27entit%C3%A9+%27belette%27+n%27existait+pas+en+base%0A'
   74    15    >   INIT_FCALL                                               'var_dump'
         16        FETCH_OBJ_R                                      ~12     !2, 'entity'
         17        SEND_VAL                                                 ~12
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

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

End of function __construct

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

End of function getname

Function setname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/90o61
function name:  setName
number of ops:  6
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   18     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   19     5*     > RETURN                                                   null

End of function setname

End of class Entity.

Class DB:
Function findbyname:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/90o61
function name:  findByName
number of ops:  9
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        IS_IDENTICAL                                             !0, 'belette'
          2      > JMPZ                                                     ~1, ->7
   26     3    >   NEW                                              $2      'Entity'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6      > RETURN                                                   $2
   28     7    > > RETURN                                                   <false>
   29     8*     > RETURN                                                   null

End of function findbyname

End of class DB.

Class class@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/90o61
function name:  __construct
number of ops:  7
compiled vars:  !0 = $entity, !1 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   56     2        ASSIGN_OBJ                                               'entity'
          3        OP_DATA                                                  !0
   57     4        ASSIGN_OBJ                                               'new'
          5        OP_DATA                                                  !1
   58     6      > RETURN                                                   null

End of function __construct

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

End of function isnew

End of class class@anonymous.

Class Test:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/90o61
function name:  __construct
number of ops:  4
compiled vars:  !0 = $db
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        ASSIGN_OBJ                                               'db'
          2        OP_DATA                                                  !0
   37     3      > RETURN                                                   null

End of function __construct

Function getentity:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/90o61
function name:  getEntity
number of ops:  29
compiled vars:  !0 = $name, !1 = $entity, !2 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        FETCH_OBJ_R                                      ~3      'db'
          2        INIT_METHOD_CALL                                         ~3, 'findByName'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !1, $4
   42     6        ASSIGN                                                   !2, <false>
   43     7        TYPE_CHECK                                    4          !1
          8      > JMPZ                                                     ~7, ->20
   44     9    >   NEW                                              $8      'Entity'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $8
   45    12        INIT_METHOD_CALL                                         !1, 'setName'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
   46    15        FETCH_OBJ_R                                      ~12     'db'
         16        INIT_METHOD_CALL                                         ~12, 'insert'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
   47    19        ASSIGN                                                   !2, <true>
   50    20    >   DECLARE_ANON_CLASS                               'findbyname'    
         21        NEW                                              $16     $15
         22        SEND_VAR_EX                                              !1
         23        SEND_VAR_EX                                              !2
         24        DO_FCALL                                      0          
         25        VERIFY_RETURN_TYPE                                       $16
         26      > RETURN                                                   $16
   65    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function getentity

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.88 ms | 1404 KiB | 15 Q