3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* note: 1. you actually might want to move the validation to a separate function, called 'validate' 2. you might want to make a class out of it, and then use class' property 'errors', but this will work fine too: 3. if you have many fields then you might want to run a loop testing all e.g. for emptiness. Or use some validation package. */ function doTheJob($formData) { $errors = []; if(!isset($formData['firstName']) || trim($formData['firstName'] === '')) { $errors[] = 'No name!'; } if(!empty($errors)){ return $errors; } //there are no issues //lets do our job and: //... return true; } $data = $_POST; //lets mock it: $data['lastName'] = 'Smith'; $result = doTheJob($data); if($result === true){//notice the THREE = echo "It's fine!!!"; }else{ echo "errors found!!! Arrggg!!!! \n"; echo implode("\n",$result); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j9Erg
function name:  (null)
number of ops:  19
compiled vars:  !0 = $data, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_R                      global              ~2      '_POST'
          1        ASSIGN                                                   !0, ~2
   25     2        ASSIGN_DIM                                               !0, 'lastName'
          3        OP_DATA                                                  'Smith'
   26     4        INIT_FCALL                                               'dothejob'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !1, $5
   27     8        TYPE_CHECK                                    8          !1
          9      > JMPZ                                                     ~7, ->12
   28    10    >   ECHO                                                     'It%27s+fine%21%21%21'
         11      > JMP                                                      ->18
   30    12    >   ECHO                                                     'errors+found%21%21%21+Arrggg%21%21%21%21+%0A'
   31    13        INIT_FCALL                                               'implode'
         14        SEND_VAL                                                 '%0A'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $8      
         17        ECHO                                                     $8
   32    18    > > RETURN                                                   1

Function dothejob:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 11
filename:       /in/j9Erg
function name:  doTheJob
number of ops:  20
compiled vars:  !0 = $formData, !1 = $errors
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        ASSIGN                                                   !1, <array>
   11     2        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      !0, 'firstName'
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPNZ_EX                                         ~4      ~4, ->11
          5    >   INIT_FCALL                                               'trim'
          6        FETCH_DIM_R                                      ~5      !0, 'firstName'
          7        IS_IDENTICAL                                     ~6      ~5, ''
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                         $7      
         10        BOOL                                             ~4      $7
         11    > > JMPZ                                                     ~4, ->14
   12    12    >   ASSIGN_DIM                                               !1
         13        OP_DATA                                                  'No+name%21'
   14    14    >   ISSET_ISEMPTY_CV                                 ~9      !1
         15        BOOL_NOT                                         ~10     ~9
         16      > JMPZ                                                     ~10, ->18
   15    17    > > RETURN                                                   !1
   20    18    > > RETURN                                                   <true>
   21    19*     > RETURN                                                   null

End of function dothejob

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.3 ms | 1403 KiB | 18 Q