3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 'id' => '4c44c3e074ffc928250576cc', 'name' => 'Salvation Army', 'contact' => array( 'phone' => '2122899617', 'formattedPhone' => '(212) 289-9617' ), 'location' => array ( 'address' => '26 E 125th St', 'crossStreet' => 'btw Madison & 5th Ave', 'lat' => '40.805853703834', 'lng' => '-73.941053819056', 'distance' => '53', 'postalCode' => '10035', 'cc' => 'US', 'city' => 'New York', 'state' => 'NY', 'country' => 'United States' ), 'categories' => Array ( [ 'id' => '4bf58dd8d48988d101951735', 'name' => 'Thrift / Vintage Store', 'pluralName' => 'Thrift / Vintage Stores', 'shortName' => 'Thrift / Vintage', 'icon' => array ( 'prefix' => 'https://ss1.4sqi.net/img/categories_v2/shops/default_', 'suffix' => '.png' ), 'primary' => '1', ] ), 'verified' => '', 'restricted' => '1', 'stats' => array ( 'checkinsCount' => '71', 'usersCount' => '46', 'tipCount' => '3' ), 'specials' => array ( 'count' => '0', 'items' => Array() ), 'hereNow' => array ( 'count' => '0', 'groups' => Array() ), 'referralId' => 'v-1393405742' ); class Venue { protected $id; protected $categories; protected $contact; protected $fourSquareVenueId; protected $location; protected $name; protected $statistics; public function __construct() { $this->categories = []; } /** * Get id * * @return id $id */ public function getId() { return $this->id; } /** * Add category * * @param \Trist\Bundle\CommonBundle\Document\Venue\VenueCategory $category */ public function addCategory( $category) { $this->categories[] = $category; } /** * Remove category * * @param \Trist\Bundle\CommonBundle\Document\Venue\VenueCategory $category */ public function removeCategory($category) { $this->categories->removeElement($category); } /** * Get categories * * @return \Doctrine\Common\Collections\ArrayCollection $categories */ public function getCategories() { return $this->categories; } /** * Set contact * * @param \Trist\Bundle\CommonBundle\Document\Venue\VenueContact $contact * @return self */ public function setContact($contact) { $this->contact = $contact; return $this; } } function cast($destination, $sourceObject) { if (is_string($destination)) { $destination = new $destination(); } $sourceReflection = new ReflectionObject($sourceObject); $destinationReflection = new ReflectionObject($destination); $sourceProperties = $sourceReflection->getProperties(); foreach ($sourceProperties as $sourceProperty) { $sourceProperty->setAccessible(true); $name = $sourceProperty->getName(); $value = $sourceProperty->getValue($sourceObject); if ($destinationReflection->hasProperty($name)) { $propDest = $destinationReflection->getProperty($name); $propDest->setAccessible(true); $propDest->setValue($destination,$value); } else { $destination->$name = $value; } } return $destination; } $obj = json_decode(json_encode($arr)); $o2 = cast('Venue', $obj); print_r($o2); echo $o2->getId();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UcSHU
function name:  (null)
number of ops:  20
compiled vars:  !0 = $arr, !1 = $obj, !2 = $o2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
  153     1        INIT_FCALL                                               'json_decode'
          2        INIT_FCALL                                               'json_encode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        SEND_VAR                                                 $4
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !1, $5
  154     8        INIT_FCALL                                               'cast'
          9        SEND_VAL                                                 'Venue'
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !2, $7
  156    13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
  157    16        INIT_METHOD_CALL                                         !2, 'getId'
         17        DO_FCALL                                      0  $10     
         18        ECHO                                                     $10
         19      > RETURN                                                   1

Function cast:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 50
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 50
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 47
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 8
filename:       /in/UcSHU
function name:  cast
number of ops:  53
compiled vars:  !0 = $destination, !1 = $sourceObject, !2 = $sourceReflection, !3 = $destinationReflection, !4 = $sourceProperties, !5 = $sourceProperty, !6 = $name, !7 = $value, !8 = $propDest
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  130     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  132     2        TYPE_CHECK                                   64          !0
          3      > JMPZ                                                     ~9, ->8
  133     4    >   FETCH_CLASS                                   0  $10     !0
          5        NEW                                              $11     $10
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $11
  135     8    >   NEW                                              $14     'ReflectionObject'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $14
  136    12        NEW                                              $17     'ReflectionObject'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !3, $17
  137    16        INIT_METHOD_CALL                                         !2, 'getProperties'
         17        DO_FCALL                                      0  $20     
         18        ASSIGN                                                   !4, $20
  138    19      > FE_RESET_R                                       $22     !4, ->50
         20    > > FE_FETCH_R                                               $22, !5, ->50
  139    21    >   INIT_METHOD_CALL                                         !5, 'setAccessible'
         22        SEND_VAL_EX                                              <true>
         23        DO_FCALL                                      0          
  140    24        INIT_METHOD_CALL                                         !5, 'getName'
         25        DO_FCALL                                      0  $24     
         26        ASSIGN                                                   !6, $24
  141    27        INIT_METHOD_CALL                                         !5, 'getValue'
         28        SEND_VAR_EX                                              !1
         29        DO_FCALL                                      0  $26     
         30        ASSIGN                                                   !7, $26
  142    31        INIT_METHOD_CALL                                         !3, 'hasProperty'
         32        SEND_VAR_EX                                              !6
         33        DO_FCALL                                      0  $28     
         34      > JMPZ                                                     $28, ->47
  143    35    >   INIT_METHOD_CALL                                         !3, 'getProperty'
         36        SEND_VAR_EX                                              !6
         37        DO_FCALL                                      0  $29     
         38        ASSIGN                                                   !8, $29
  144    39        INIT_METHOD_CALL                                         !8, 'setAccessible'
         40        SEND_VAL_EX                                              <true>
         41        DO_FCALL                                      0          
  145    42        INIT_METHOD_CALL                                         !8, 'setValue'
         43        SEND_VAR_EX                                              !0
         44        SEND_VAR_EX                                              !7
         45        DO_FCALL                                      0          
         46      > JMP                                                      ->49
  147    47    >   ASSIGN_OBJ                                               !0, !6
         48        OP_DATA                                                  !7
  138    49    > > JMP                                                      ->20
         50    >   FE_FREE                                                  $22
  150    51      > RETURN                                                   !0
  151    52*     > RETURN                                                   null

End of function cast

Class Venue:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UcSHU
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   ASSIGN_OBJ                                               'categories'
          1        OP_DATA                                                  <array>
   75     2      > RETURN                                                   null

End of function __construct

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

End of function getid

Function addcategory:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UcSHU
function name:  addCategory
number of ops:  5
compiled vars:  !0 = $category
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   RECV                                             !0      
   94     1        FETCH_OBJ_W                                      $1      'categories'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   95     4      > RETURN                                                   null

End of function addcategory

Function removecategory:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UcSHU
function name:  removeCategory
number of ops:  6
compiled vars:  !0 = $category
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  102     0  E >   RECV                                             !0      
  104     1        FETCH_OBJ_R                                      ~1      'categories'
          2        INIT_METHOD_CALL                                         ~1, 'removeElement'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
  105     5      > RETURN                                                   null

End of function removecategory

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

End of function getcategories

Function setcontact:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UcSHU
function name:  setContact
number of ops:  6
compiled vars:  !0 = $contact
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  123     0  E >   RECV                                             !0      
  125     1        ASSIGN_OBJ                                               'contact'
          2        OP_DATA                                                  !0
  126     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
  127     5*     > RETURN                                                   null

End of function setcontact

End of class Venue.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.22 ms | 1411 KiB | 20 Q