Answers for "php object creation"

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
3

make a object php

$object = new stdClass();
   $object->property = 'Here we go';

   var_dump($object);
   /*
   outputs:

   object(stdClass)#2 (1) {
      ["property"]=>
      string(10) "Here we go"
    }
   */
Posted by: Guest on May-04-2020
0

object php

//object init
  $object = (object) [
    'propertyOne' => 'foo',
    'propertyTwo' => 42,
  ];
Posted by: Guest on June-16-2020
0

php new object

By far the easiest and correct way to instantiate an empty generic php object that you can then modify for whatever purpose you choose:



<?php $genericObject = new stdClass(); ?>



I had the most difficult time finding this, hopefully it will help someone else!
Posted by: Guest on April-24-2020

Browse Popular Code Answers by Language