3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class User { public const STATUS_ACTIVE = 'active'; public const STATUS_INACTIVE = 'inactive'; public function __construct(public string $username, public string $status = self::STATUS_ACTIVE) { } public function setStatus(string $status): void { assert( in_array($status, [self::STATUS_ACTIVE, self::STATUS_INACTIVE]), sprintf('Le status %s n\'est pas valide. Les status possibles sont : %s', $status, implode(‘, ‘, [self::STATUS_ACTIVE, self::STATUS_INACTIVE])) ); $this->status = $status; } public function getStatus(): string { return $this->status; } } class Admin extends User { // Ajout d'un tableau de roles pour affiner les droits des administrateurs :) public function __construct(public string $username, public array $roles = [], public string $status = self::STATUS_ACTIVE) { } // Méthode d'ajout d'un rôle, puis on supprime les doublons avec array_filter. public function addRole(string $role): void { $this->roles[] = $role; $this->roles = array_filter($this->roles); } // Méthode de renvoie des rôles, dans lequel on définit le rôle ADMIN par défaut. public function getRoles(): array { $roles = $this->roles; $roles[] = 'ADMIN'; return $roles; } public function setRoles(array $roles): void { $this->roles = $roles; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E > > RETURN                                                   1

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

End of function __construct

Function setstatus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  setStatus
number of ops:  22
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
   17     3        IN_ARRAY                                         ~1      !0, <array>
          4        SEND_VAL                                                 ~1
   18     5        INIT_FCALL                                               'sprintf'
          6        SEND_VAL                                                 'Le+status+%25s+n%27est+pas+valide.+Les+status+possibles+sont+%3A+%25s'
          7        SEND_VAR                                                 !0
          8        INIT_FCALL                                               'implode'
          9        FETCH_CONSTANT                                   ~2      '%E2%80%98'
         10        SEND_VAL                                                 ~2
         11        FETCH_CONSTANT                                   ~3      '%E2%80%98'
         12        SEND_VAL                                                 ~3
         13        SEND_VAL                                                 <array>
         14        DO_ICALL                                         $4      
         15        SEND_VAR                                                 $4
         16        DO_ICALL                                         $5      
         17        SEND_VAR                                                 $5
   16    18        DO_ICALL                                                 
   21    19        ASSIGN_OBJ                                               'status'
         20        OP_DATA                                                  !0
   22    21      > RETURN                                                   null

End of function setstatus

Function getstatus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  getStatus
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   27     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getstatus

End of class User.

Class Admin:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  __construct
number of ops:  10
compiled vars:  !0 = $username, !1 = $roles, !2 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
          2        RECV_INIT                                        !2      <const ast>
          3        ASSIGN_OBJ                                               'username'
          4        OP_DATA                                                  !0
          5        ASSIGN_OBJ                                               'roles'
          6        OP_DATA                                                  !1
          7        ASSIGN_OBJ                                               'status'
          8        OP_DATA                                                  !2
   35     9      > RETURN                                                   null

End of function __construct

Function addrole:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  addRole
number of ops:  11
compiled vars:  !0 = $role
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        FETCH_OBJ_W                                      $1      'roles'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   41     4        INIT_FCALL                                               'array_filter'
          5        FETCH_OBJ_R                                      ~4      'roles'
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                         $5      
          8        ASSIGN_OBJ                                               'roles'
          9        OP_DATA                                                  $5
   42    10      > RETURN                                                   null

End of function addrole

Function getroles:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  getRoles
number of ops:  8
compiled vars:  !0 = $roles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~1      'roles'
          1        ASSIGN                                                   !0, ~1
   48     2        ASSIGN_DIM                                               !0
          3        OP_DATA                                                  'ADMIN'
   50     4        VERIFY_RETURN_TYPE                                       !0
          5      > RETURN                                                   !0
   51     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function getroles

Function setroles:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  setRoles
number of ops:  4
compiled vars:  !0 = $roles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   55     1        ASSIGN_OBJ                                               'roles'
          2        OP_DATA                                                  !0
   56     3      > RETURN                                                   null

End of function setroles

Function setstatus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  setStatus
number of ops:  22
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
   17     3        IN_ARRAY                                         ~1      !0, <array>
          4        SEND_VAL                                                 ~1
   18     5        INIT_FCALL                                               'sprintf'
          6        SEND_VAL                                                 'Le+status+%25s+n%27est+pas+valide.+Les+status+possibles+sont+%3A+%25s'
          7        SEND_VAR                                                 !0
          8        INIT_FCALL                                               'implode'
          9        FETCH_CONSTANT                                   ~2      '%E2%80%98'
         10        SEND_VAL                                                 ~2
         11        FETCH_CONSTANT                                   ~3      '%E2%80%98'
         12        SEND_VAL                                                 ~3
         13        SEND_VAL                                                 <array>
         14        DO_ICALL                                         $4      
         15        SEND_VAR                                                 $4
         16        DO_ICALL                                         $5      
         17        SEND_VAR                                                 $5
   16    18        DO_ICALL                                                 
   21    19        ASSIGN_OBJ                                               'status'
         20        OP_DATA                                                  !0
   22    21      > RETURN                                                   null

End of function setstatus

Function getstatus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mR3Q6
function name:  getStatus
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   27     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getstatus

End of class Admin.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.13 ms | 1471 KiB | 17 Q