3v4l.org

run code in 500+ 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
          2        CAST                                              8  ~5      <array>
          3        ADD_ARRAY_ELEMENT                                    ~4      ~5
          4        CAST                                              8  ~6      <array>
          5        ADD_ARRAY_ELEMENT                                    ~4      ~6
          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 = 14
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/Jlu7s
function name:  hasPropertyValue
number of ops:  18
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, ->14
          4    > > FE_FETCH_R                                                   $4, !3, ->14
   15     5    >   FRAMELESS_ICALL_2                property_exists      ~5      !3, !1
          6      > JMPZ_EX                                              ~5      ~5, ->10
          7    >   FETCH_OBJ_R                                          ~6      !3, !1
          8        IS_IDENTICAL                                         ~7      !2, ~6
          9        BOOL                                                 ~5      ~7
         10    > > JMPZ                                                         ~5, ->13
   16    11    >   FE_FREE                                                      $4
         12      > RETURN                                                       <true>
   14    13    > > JMP                                                          ->4
         14    >   FE_FREE                                                      $4
   19    15      > RETURN                                                       <false>
   20    16*       VERIFY_RETURN_TYPE                                           
         17*     > RETURN                                                       null

End of function haspropertyvalue

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.11 ms | 2145 KiB | 16 Q