3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class User { protected const STATUS_ACTIVE = 'active'; protected const STATUS_INACTIVE = 'inactive'; public function __construct(protected string $username, protected string $status = self::STATUS_ACTIVE) { } protected 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; } protected function getStatus(): string { return $this->status; } } class Admin extends User { public const STATUS_LOCKED = 'locked'; // la méthode est entièrement ré-écrite ici :) seule la signature reste inchangée public function setStatus(string $status): void { assert( in_array($status, [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_LOCKED]), sprintf('Le status %s n\'est pas valide. Les status possibles sont : %s', $status, implode(', ', [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_LOCKED])) ); $this->status = $status; } // la méthode utilise celle de la classe parente, et ajoute un comportement :) public function getStatus(): string { return strtoupper(parent::getStatus()); } } $admin = new Admin('Paddington'); $admin->setStatus(Admin::STATUS_LOCKED); echo $admin->getStatus();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SiNBJ
function name:  (null)
number of ops:  11
compiled vars:  !0 = $admin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   NEW                                              $1      'Admin'
          1        SEND_VAL_EX                                              'Paddington'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   55     4        INIT_METHOD_CALL                                         !0, 'setStatus'
          5        SEND_VAL_EX                                              'locked'
          6        DO_FCALL                                      0          
   56     7        INIT_METHOD_CALL                                         !0, 'getStatus'
          8        DO_FCALL                                      0  $5      
          9        ECHO                                                     $5
         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/SiNBJ
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/SiNBJ
function name:  setStatus
number of ops:  19
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        SEND_VAL                                                 '%2C+'
         10        SEND_VAL                                                 <array>
         11        DO_ICALL                                         $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                         $3      
         14        SEND_VAR                                                 $3
   16    15        DO_ICALL                                                 
   21    16        ASSIGN_OBJ                                               'status'
         17        OP_DATA                                                  !0
   22    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/SiNBJ
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 setstatus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SiNBJ
function name:  setStatus
number of ops:  32
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
   39     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        ADD_ARRAY_ELEMENT                                ~2      'locked'
         10        SEND_VAL                                                 ~2
         11        DO_ICALL                                         $4      
         12        SEND_VAR                                                 $4
   40    13        INIT_FCALL                                               'sprintf'
         14        SEND_VAL                                                 'Le+status+%25s+n%27est+pas+valide.+Les+status+possibles+sont+%3A+%25s'
         15        SEND_VAR                                                 !0
         16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '%2C+'
         18        FETCH_CLASS_CONSTANT                             ~5      'STATUS_ACTIVE'
         19        INIT_ARRAY                                       ~6      ~5
         20        FETCH_CLASS_CONSTANT                             ~7      'STATUS_INACTIVE'
         21        ADD_ARRAY_ELEMENT                                ~6      ~7
         22        ADD_ARRAY_ELEMENT                                ~6      'locked'
         23        SEND_VAL                                                 ~6
         24        DO_ICALL                                         $8      
         25        SEND_VAR                                                 $8
         26        DO_ICALL                                         $9      
         27        SEND_VAR                                                 $9
   38    28        DO_ICALL                                                 
   43    29        ASSIGN_OBJ                                               'status'
         30        OP_DATA                                                  !0
   44    31      > 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/SiNBJ
function name:  getStatus
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                               'strtoupper'
          1        INIT_STATIC_METHOD_CALL                                  'getStatus'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                         $1      
          5        VERIFY_RETURN_TYPE                                       $1
          6      > RETURN                                                   $1
   50     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function getstatus

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SiNBJ
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

End of class Admin.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.24 ms | 1466 KiB | 18 Q