3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ClientController { function __construct($clients) { foreach ($clients as $key => $value) { $clients[$key]['name_valid'] = $this->validName($value['name']); $clients[$key]['cpf_valid'] = $this->validCpf($value['cpf']); $clients[$key]['birth_date_valid'] = $this->validBirthdate($value['birth_date']); $clients[$key]['email_valid'] = $this->validEmail($value['email']); } print_r($clients); } function validName($name) { return (!empty($name) && !preg_match("/^[a-zA-Z'-]+$/", $name)); } function validCpf($cpf) { return (!empty($cpf) && ctype_digit($cpf)); } function validBirthdate($date) { return (!empty($birthdate) && preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/", $birthdate)); } function validEmail($email) { return (filter_var($email, FILTER_VALIDATE_EMAIL)); } } class ClientModel { private $name; private $cpf; private $birth_date; private $email; public function __construct($name, $cpf, $birth_date, $email) { $this->setName($name); $this->setCpf($cpf); $this->setBirthDate($birth_date); $this->setEmail($email); } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function getCpf() { return $this->cpf; } public function setCpf($cpf) { $this->cpf = $cpf; } public function getBirthDate() { return $this->birth_date; } public function setBirthDate($birth_date) { $this->birth_date = $birth_date; } public function getEmail() { return $this->email; } public function setEmail($email) { $this->email = $email; } } class ClientCollection { private $_clients = []; public function add(ClientModel $client) { $this->_clients[] = $client; end($this->_clients); return key($this->_clients); } public function get($key) { if (isset($this->_clients[$key])) { return $this->_clients[$key]; } else { throw new Exception("Client does not exist"); } } public function delete($key) { if (isset($this->_clients[$key])) { unset($this->_clients[$key]); } else { throw new Exception("Client does not exist"); } } } $clients = array( array("name" => "Hubert Adams", "cpf" => "86383860011", "birth_date" => "20/07/2015", "email" => "carlee_fadel@block.name"), array("name" => "Isabelle Mann", "cpf" => "58958058684", "birth_date" => "27/07/2015", "email" => "dortha.pacocha@ebert.biz"), array("name" => "Jayda Reichert", "cpf" => "01075384664", "birth_date" => "24/07/2015", "email" => "kaylie@stehrgaylord.biz"), array("name" => "Brionna Reinger", "cpf" => "48991299636", "birth_date" => "22/07/2015", "email" => "ansley.orn@herzog.org"), array("name" => "Diego", "cpf" => "55483741684aaaa", "birth_date" => "", "email" => "raoul mills com") ); $collection = new ClientCollection(); foreach ($clients as $client) { $model = new ClientModel($client['name'], $client['cpf'], $client['birth_date'], $client['email']); $collection->add($model); } var_dump($collection);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 25
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 25
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/LpnMv
function name:  (null)
number of ops:  30
compiled vars:  !0 = $clients, !1 = $collection, !2 = $client, !3 = $model
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   ASSIGN                                                   !0, <array>
  105     1        NEW                                              $5      'ClientCollection'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
  106     4      > FE_RESET_R                                       $8      !0, ->25
          5    > > FE_FETCH_R                                               $8, !2, ->25
  107     6    >   NEW                                              $9      'ClientModel'
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $10     !2, 'name'
          9        SEND_FUNC_ARG                                            $10
         10        CHECK_FUNC_ARG                                           
         11        FETCH_DIM_FUNC_ARG                               $11     !2, 'cpf'
         12        SEND_FUNC_ARG                                            $11
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $12     !2, 'birth_date'
         15        SEND_FUNC_ARG                                            $12
         16        CHECK_FUNC_ARG                                           
         17        FETCH_DIM_FUNC_ARG                               $13     !2, 'email'
         18        SEND_FUNC_ARG                                            $13
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !3, $9
  108    21        INIT_METHOD_CALL                                         !1, 'add'
         22        SEND_VAR_EX                                              !3
         23        DO_FCALL                                      0          
  106    24      > JMP                                                      ->5
         25    >   FE_FREE                                                  $8
  111    26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Class ClientController:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 37
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 37
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/LpnMv
function name:  __construct
number of ops:  42
compiled vars:  !0 = $clients, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1      > FE_RESET_R                                       $3      !0, ->37
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->37
          3    >   ASSIGN                                                   !2, ~4
    8     4        INIT_METHOD_CALL                                         'validName'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_DIM_FUNC_ARG                               $8      !1, 'name'
          7        SEND_FUNC_ARG                                            $8
          8        DO_FCALL                                      0  $9      
          9        FETCH_DIM_W                                      $6      !0, !2
         10        ASSIGN_DIM                                               $6, 'name_valid'
         11        OP_DATA                                                  $9
    9    12        INIT_METHOD_CALL                                         'validCpf'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $12     !1, 'cpf'
         15        SEND_FUNC_ARG                                            $12
         16        DO_FCALL                                      0  $13     
         17        FETCH_DIM_W                                      $10     !0, !2
         18        ASSIGN_DIM                                               $10, 'cpf_valid'
         19        OP_DATA                                                  $13
   10    20        INIT_METHOD_CALL                                         'validBirthdate'
         21        CHECK_FUNC_ARG                                           
         22        FETCH_DIM_FUNC_ARG                               $16     !1, 'birth_date'
         23        SEND_FUNC_ARG                                            $16
         24        DO_FCALL                                      0  $17     
         25        FETCH_DIM_W                                      $14     !0, !2
         26        ASSIGN_DIM                                               $14, 'birth_date_valid'
         27        OP_DATA                                                  $17
   11    28        INIT_METHOD_CALL                                         'validEmail'
         29        CHECK_FUNC_ARG                                           
         30        FETCH_DIM_FUNC_ARG                               $20     !1, 'email'
         31        SEND_FUNC_ARG                                            $20
         32        DO_FCALL                                      0  $21     
         33        FETCH_DIM_W                                      $18     !0, !2
         34        ASSIGN_DIM                                               $18, 'email_valid'
         35        OP_DATA                                                  $21
    7    36      > JMP                                                      ->2
         37    >   FE_FREE                                                  $3
   13    38        INIT_FCALL                                               'print_r'
         39        SEND_VAR                                                 !0
         40        DO_ICALL                                                 
   14    41      > RETURN                                                   null

End of function __construct

Function validname:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/LpnMv
function name:  validName
number of ops:  12
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ_EX                                          ~2      ~2, ->10
          4    >   INIT_FCALL                                               'preg_match'
          5        SEND_VAL                                                 '%2F%5E%5Ba-zA-Z%27-%5D%2B%24%2F'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8        BOOL_NOT                                         ~4      $3
          9        BOOL                                             ~2      ~4
         10    > > RETURN                                                   ~2
   18    11*     > RETURN                                                   null

End of function validname

Function validcpf:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/LpnMv
function name:  validCpf
number of ops:  10
compiled vars:  !0 = $cpf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ_EX                                          ~2      ~2, ->8
          4    >   INIT_FCALL                                               'ctype_digit'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        BOOL                                             ~2      $3
          8    > > RETURN                                                   ~2
   22     9*     > RETURN                                                   null

End of function validcpf

Function validbirthdate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/LpnMv
function name:  validBirthdate
number of ops:  11
compiled vars:  !0 = $date, !1 = $birthdate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ISSET_ISEMPTY_CV                                 ~2      !1
          2        BOOL_NOT                                         ~3      ~2
          3      > JMPZ_EX                                          ~3      ~3, ->9
          4    >   INIT_FCALL                                               'preg_match'
          5        SEND_VAL                                                 '%2F%5E%5B0-9%5D%7B1%2C2%7D%5C%2F%5B0-9%5D%7B1%2C2%7D%5C%2F%5B0-9%5D%7B4%7D%24%2F'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        BOOL                                             ~3      $4
          9    > > RETURN                                                   ~3
   26    10*     > RETURN                                                   null

End of function validbirthdate

Function validemail:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LpnMv
function name:  validEmail
number of ops:  7
compiled vars:  !0 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'filter_var'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 274
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   30     6*     > RETURN                                                   null

End of function validemail

End of class ClientController.

Class ClientModel:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LpnMv
function name:  __construct
number of ops:  17
compiled vars:  !0 = $name, !1 = $cpf, !2 = $birth_date, !3 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   40     4        INIT_METHOD_CALL                                         'setName'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   41     7        INIT_METHOD_CALL                                         'setCpf'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
   42    10        INIT_METHOD_CALL                                         'setBirthDate'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0          
   43    13        INIT_METHOD_CALL                                         'setEmail'
         14        SEND_VAR_EX                                              !3
         15        DO_FCALL                                      0          
   44    16      > 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/LpnMv
function name:  getName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
   48     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/LpnMv
function name:  setName
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   50     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   51     3      > RETURN                                                   null

End of function setname

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

End of function getcpf

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

End of function setcpf

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

End of function getbirthdate

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

End of function setbirthdate

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

End of function getemail

Function setemail:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LpnMv
function name:  setEmail
number of ops:  4
compiled vars:  !0 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
   68     1        ASSIGN_OBJ                                               'email'
          2        OP_DATA                                                  !0
   69     3      > RETURN                                                   null

End of function setemail

End of class ClientModel.

Class ClientCollection:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LpnMv
function name:  add
number of ops:  14
compiled vars:  !0 = $client
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
   77     1        FETCH_OBJ_W                                      $1      '_clients'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   78     4        INIT_FCALL                                               'end'
          5        FETCH_OBJ_W                                      $3      '_clients'
          6        SEND_REF                                                 $3
          7        DO_ICALL                                                 
   79     8        INIT_FCALL                                               'key'
          9        FETCH_OBJ_R                                      ~5      '_clients'
         10        SEND_VAL                                                 ~5
         11        DO_ICALL                                         $6      
         12      > RETURN                                                   $6
   80    13*     > RETURN                                                   null

End of function add

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/LpnMv
function name:  get
number of ops:  13
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
   82     1        FETCH_OBJ_IS                                     ~1      '_clients'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->8
   83     4    >   FETCH_OBJ_R                                      ~3      '_clients'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
          7*       JMP                                                      ->12
   85     8    >   NEW                                              $5      'Exception'
          9        SEND_VAL_EX                                              'Client+does+not+exist'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $5
   87    12*     > RETURN                                                   null

End of function get

Function delete:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/LpnMv
function name:  delete
number of ops:  12
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   RECV                                             !0      
   89     1        FETCH_OBJ_IS                                     ~1      '_clients'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
   90     4    >   FETCH_OBJ_UNSET                                  $3      '_clients'
          5        UNSET_DIM                                                $3, !0
          6      > JMP                                                      ->11
   92     7    >   NEW                                              $4      'Exception'
          8        SEND_VAL_EX                                              'Client+does+not+exist'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
   94    11    > > RETURN                                                   null

End of function delete

End of class ClientCollection.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
215.09 ms | 1420 KiB | 27 Q