3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); abstract class User { public const STATUS_ACTIVE = 'active'; public const STATUS_INACTIVE = 'inactive'; public function __construct(public string $email, public string $status = self::STATUS_ACTIVE) { } // le mot clé self a été modifié pour le mot clé static dans la méthode :) public function setStatus(string $status): void { assert( in_array($status, [static::STATUS_ACTIVE, static::STATUS_INACTIVE]), sprintf('Le status %s n\'est pas valide. Les status possibles sont : %s', $status, implode(', ',[static::STATUS_ACTIVE, static::STATUS_INACTIVE])) ); $this->status = $status; } public function getStatus(): string { return $this->status; } abstract public function getUsername(): string; } final class Admin extends User { public const STATUS_ACTIVE = 'is_active'; public const STATUS_INACTIVE = 'is_inactive'; // Ajout d'un tableau de roles pour affiner les droits des administrateurs :) public function __construct(string $email, string $status = self::STATUS_ACTIVE, public array $roles = []) { parent::__construct($email, $status); } public function getUsername(): string { return $this->email; } // ... } $admin = new Admin('michel@petrucciani.com'); var_dump($admin); $admin->setStatus(Admin::STATUS_INACTIVE);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lCcX
function name:  (null)
number of ops:  11
compiled vars:  !0 = $admin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   NEW                                              $1      'Admin'
          1        SEND_VAL_EX                                              'michel%40petrucciani.com'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   53     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   54     7        INIT_METHOD_CALL                                         !0, 'setStatus'
          8        SEND_VAL_EX                                              'is_inactive'
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Class User:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lCcX
function name:  __construct
number of ops:  7
compiled vars:  !0 = $email, !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                                               'email'
          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/2lCcX
function name:  setStatus
number of ops:  30
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
   18     3        INIT_FCALL                                               'in_array'
          4        SEND_VAR                                                 !0
          5        FETCH_CLASS_CONSTANT                             ~1      'STATUS_ACTIVE'
          6        INIT_ARRAY                                       ~2      ~1
          7        FETCH_CLASS_CONSTANT                             ~3      'STATUS_INACTIVE'
          8        ADD_ARRAY_ELEMENT                                ~2      ~3
          9        SEND_VAL                                                 ~2
         10        DO_ICALL                                         $4      
         11        SEND_VAR                                                 $4
   19    12        INIT_FCALL                                               'sprintf'
         13        SEND_VAL                                                 'Le+status+%25s+n%27est+pas+valide.+Les+status+possibles+sont+%3A+%25s'
         14        SEND_VAR                                                 !0
         15        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '%2C+'
         17        FETCH_CLASS_CONSTANT                             ~5      'STATUS_ACTIVE'
         18        INIT_ARRAY                                       ~6      ~5
         19        FETCH_CLASS_CONSTANT                             ~7      'STATUS_INACTIVE'
         20        ADD_ARRAY_ELEMENT                                ~6      ~7
         21        SEND_VAL                                                 ~6
         22        DO_ICALL                                         $8      
         23        SEND_VAR                                                 $8
         24        DO_ICALL                                         $9      
         25        SEND_VAR                                                 $9
   17    26        DO_ICALL                                                 
   22    27        ASSIGN_OBJ                                               'status'
         28        OP_DATA                                                  !0
   23    29      > 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/2lCcX
function name:  getStatus
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   28     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getstatus

Function getusername:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lCcX
function name:  getUsername
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function getusername

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/2lCcX
function name:  __construct
number of ops:  10
compiled vars:  !0 = $email, !1 = $status, !2 = $roles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
          2        RECV_INIT                                        !2      <array>
          3        ASSIGN_OBJ                                               'roles'
          4        OP_DATA                                                  !2
   41     5        INIT_STATIC_METHOD_CALL                                  
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
   42     9      > RETURN                                                   null

End of function __construct

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

End of function getusername

Function setstatus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lCcX
function name:  setStatus
number of ops:  30
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
   18     3        INIT_FCALL                                               'in_array'
          4        SEND_VAR                                                 !0
          5        FETCH_CLASS_CONSTANT                             ~1      'STATUS_ACTIVE'
          6        INIT_ARRAY                                       ~2      ~1
          7        FETCH_CLASS_CONSTANT                             ~3      'STATUS_INACTIVE'
          8        ADD_ARRAY_ELEMENT                                ~2      ~3
          9        SEND_VAL                                                 ~2
         10        DO_ICALL                                         $4      
         11        SEND_VAR                                                 $4
   19    12        INIT_FCALL                                               'sprintf'
         13        SEND_VAL                                                 'Le+status+%25s+n%27est+pas+valide.+Les+status+possibles+sont+%3A+%25s'
         14        SEND_VAR                                                 !0
         15        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '%2C+'
         17        FETCH_CLASS_CONSTANT                             ~5      'STATUS_ACTIVE'
         18        INIT_ARRAY                                       ~6      ~5
         19        FETCH_CLASS_CONSTANT                             ~7      'STATUS_INACTIVE'
         20        ADD_ARRAY_ELEMENT                                ~6      ~7
         21        SEND_VAL                                                 ~6
         22        DO_ICALL                                         $8      
         23        SEND_VAR                                                 $8
         24        DO_ICALL                                         $9      
         25        SEND_VAR                                                 $9
   17    26        DO_ICALL                                                 
   22    27        ASSIGN_OBJ                                               'status'
         28        OP_DATA                                                  !0
   23    29      > 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/2lCcX
function name:  getStatus
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   28     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:
125.69 ms | 1470 KiB | 18 Q