3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[ {"recipient_name":"John D", "phone_number":"123456"}, {"recipient_name":"Doe J", "phone_number":"654321"}, {"recipient_name":"Jon Do", "phone_number":"112233"} ]'; $myLargerArray = json_decode($json, true); $myObjArray = (object)['message_recipients' => array()]; $size = count($myLargerArray); for( $j = 0; $j < $size; $j++ ) { $myRecipientsObj->recipient_name = $myLargerArray[$j]['recipient_name']; $myRecipientsObj->phone_number = $myLargerArray[$j]['phone_number']; // var_dump($myRecipientsObj); // This outputs the correct data added from [$j] array_push($myObjArray->message_recipients, clone $myRecipientsObj); var_dump($myObjArray->message_recipients); // The output shows array elements are being overwritten at each loop iteration }
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Attempt to assign property "recipient_name" on null in /in/UcITu:12 Stack trace: #0 {main} thrown in /in/UcITu on line 12
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
57.12 ms | 401 KiB | 8 Q