Skip to content

Instantly share code, notes, and snippets.

@lucatsf
Created January 11, 2022 18:07
Show Gist options
  • Save lucatsf/d0f00c3f58e30216b3335585a11e2751 to your computer and use it in GitHub Desktop.
Save lucatsf/d0f00c3f58e30216b3335585a11e2751 to your computer and use it in GitHub Desktop.
How to create a literal object in PHP
<?php
$testArray = array(
(object)array("name" => "John", "age" => function () {
return 30;
}),
(object)array("name" => "Jane", "hobby" => function() {
return "painting";
})
);
$funtionResult = $testArray[1]->hobby;
var_dump($funtionResult());
//Output
//"painting"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment