3v4l.org

run code in 300+ PHP versions simultaneously
<?php $objects = [ (object)['cats' => 2], (object)['dogs' => 2], (object)['fish' => 10], (object)['birds' => 1], ]; $needleField = 'cats'; $needleValue = 2; function hasPropertyValue(array $objects, $property, $value): bool { foreach ($objects as $object) { if (property_exists($object, $property) && $object->{$property} === $value) { return true; } } return false; } var_export( hasPropertyValue($objects, $needleField, $needleValue) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Jlu7s
function name:  (null)
number of ops:  20
compiled vars:  !0 = $objects, !1 = $needleField, !2 = $needleValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   CAST                                          8  ~3      <array>
          1        INIT_ARRAY                                       ~4      ~3
    5     2        CAST                                          8  ~5      <array>
          3        ADD_ARRAY_ELEMENT                                ~4      ~5
    6     4        CAST                                          8  ~6      <array>
          5        ADD_ARRAY_ELEMENT                                ~4      ~6
    7     6        CAST                                          8  ~7      <array>
          7        ADD_ARRAY_ELEMENT                                ~4      ~7
    3     8        ASSIGN                                                   !0, ~4
   10     9        ASSIGN                                                   !1, 'cats'
   11    10        ASSIGN                                                   !2, 2
   21    11        INIT_FCALL                                               'var_export'
   22    12        INIT_FCALL                                               'haspropertyvalue'
         13        SEND_VAR                                                 !0
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !2
         16        DO_FCALL                                      0  $11     
         17        SEND_VAR                                                 $11
   21    18        DO_ICALL                                                 
   23    19      > RETURN                                                   1

Function haspropertyvalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 17
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/Jlu7s
function name:  hasPropertyValue
number of ops:  21
compiled vars:  !0 = $objects, !1 = $property, !2 = $value, !3 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   14     3      > FE_RESET_R                                       $4      !0, ->17
          4    > > FE_FETCH_R                                               $4, !3, ->17
   15     5    >   INIT_FCALL                                               'property_exists'
          6        SEND_VAR                                                 !3
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $5      
          9      > JMPZ_EX                                          ~6      $5, ->13
         10    >   FETCH_OBJ_R                                      ~7      !3, !1
         11        IS_IDENTICAL                                     ~8      !2, ~7
         12        BOOL                                             ~6      ~8
         13    > > JMPZ                                                     ~6, ->16
   16    14    >   FE_FREE                                                  $4
         15      > RETURN                                                   <true>
   14    16    > > JMP                                                      ->4
         17    >   FE_FREE                                                  $4
   19    18      > RETURN                                                   <false>
   20    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function haspropertyvalue

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.42 ms | 1006 KiB | 16 Q