3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class Admin { private const STATUS_ACTIVE = 'active'; private const STATUS_INACTIVE = 'inactive'; // Ajout d'un tableau de roles pour affiner les droits des administrateurs :) public function __construct(public string $username, private array $roles = [], private 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; } // 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éfini le role ADMIN par défaut. public function getRoles(): array { $roles = $this->roles; $roles[] = 'ADMIN'; return $roles; } public function setRoles(array $roles): void { $this->roles = $roles; } } $a = new Admin('Bobby'); var_dump($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BUdlL
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   NEW                                              $1      'Admin'
          1        SEND_VAL_EX                                              'Bobby'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   54     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Class Admin:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BUdlL
function name:  __construct
number of ops:  10
compiled vars:  !0 = $username, !1 = $roles, !2 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     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
   14     9      > 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/BUdlL
function name:  setStatus
number of ops:  19
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
   19     3        IN_ARRAY                                         ~1      !0, <array>
          4        SEND_VAL                                                 ~1
   20     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        SEND_VAL                                                 '%2C+'
         10        SEND_VAL                                                 <array>
         11        DO_ICALL                                         $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                         $3      
         14        SEND_VAR                                                 $3
   18    15        DO_ICALL                                                 
   23    16        ASSIGN_OBJ                                               'status'
         17        OP_DATA                                                  !0
   24    18      > 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/BUdlL
function name:  getStatus
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   29     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getstatus

Function addrole:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BUdlL
function name:  addRole
number of ops:  11
compiled vars:  !0 = $role
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        FETCH_OBJ_W                                      $1      'roles'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   35     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
   36    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/BUdlL
function name:  getRoles
number of ops:  8
compiled vars:  !0 = $roles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   FETCH_OBJ_R                                      ~1      'roles'
          1        ASSIGN                                                   !0, ~1
   42     2        ASSIGN_DIM                                               !0
          3        OP_DATA                                                  'ADMIN'
   44     4        VERIFY_RETURN_TYPE                                       !0
          5      > RETURN                                                   !0
   45     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/BUdlL
function name:  setRoles
number of ops:  4
compiled vars:  !0 = $roles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1        ASSIGN_OBJ                                               'roles'
          2        OP_DATA                                                  !0
   50     3      > RETURN                                                   null

End of function setroles

End of class Admin.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.22 ms | 1466 KiB | 18 Q