Answers for "create a object 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
4

php define object

$x = new stdClass();
Posted by: Guest on February-19-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

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
2

php object example

<?php
class Bike
{
    function model()
    {
        $model_name = 'cd100';
        echo "bike model:$model_name";
    }
}
$obj = new Bike();
$obj->model();
?>
Posted by: Guest on September-03-2021

Browse Popular Code Answers by Language