Answers for "how to 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
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
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

Code answers related to "how to create a object in php"

Browse Popular Code Answers by Language