Answers for "create object from class in php"

PHP
5

php create object

$x = (object) [
    'a' => 'test',
    'b' => 'test2',
    'c' => 'test3'
];
var_dump($x);

/*
object(stdClass)#1 (3) {
  ["a"]=>
  string(4) "test"
  ["b"]=>
  string(5) "test2"
  ["c"]=>
  string(5) "test3"
}
*/
Posted by: Guest on November-11-2020
1

php create object without clas

//create a person object in PHP
$person=new stdClass();
$person->firstName="Chuck";
$person->lastName="Bartowski";
$person->age=27;

print_r($person);
Posted by: Guest on August-06-2019

Code answers related to "create object from class in php"

Browse Popular Code Answers by Language