Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create Object in PHP? [closed]

Tags:

object

php

I want to know how can I create object like below example. Please help me to create object. I searched in google but I didn't get what I want. I'm noob.

{
    "ERROR_CODE" = 0;
    "M_USER" = {
        "CREATE_DATE" = "2018-05-09 13:57:49";
        "CREATE_USER_ID" = t1074567;
        "FACE_PICTURE_FILE_PATH" = "<null>";
        "MAIL_ADDRESS" = "[email protected]";
        "NATIVE_LANGUAGE_CD" = 102;
        "REQ_LANGUAGE_CD" = 102;
        "TERMINAL_ID" = "C71B456F-EA16-4734-8C9B-00B0856143DA";
        "TERMINAL_TYPE" = 1;
        "TOTAL_GRADE" = 0;
        "TRANSLATABLE_FLG" = 1;
        "UPDATE_DATE" = "2018-05-09 13:57:49";
        "UPDATE_USER_ID" = tdu1074567;
        "USER_ID" = tdu1074567;
        "USER_NAME" = Testing;
        "USER_PWD" = testing123;
        "VALID_FLG" = 1;
    };
    "TRANS_LANGUAGE" = (
        {
            C = 102;
            L = 10203;
        },
        {
            C = 101;
            L = 10101;
        }
    );
}  
like image 705
Kyaw Zin Wai Avatar asked May 09 '18 07:05

Kyaw Zin Wai


People also ask

How do you close an object in PHP?

Using the PHP unset() function, we can delete an object. So with the PHP unset() function, putting the object that we want to delete as the parameter to this function, we can delete this object. This is shown below. So in the above code, we delete an object named $object1.

How do you create an object in PHP?

Objects of a class is created using the new keyword.

Can we create object without class in PHP?

Using new stdClass() to create an object without class: For creating an object without a class, we will use a new stdClass() operator and then add some properties to them. Syntax: // Creating an object $object = new stdClass(); // Property added to the object $object->property = 'Property_value';

Why do we create objects in PHP?

In PHP, Object is a compound data type (along with arrays). Values of more than one types can be stored together in a single variable. Object is an instance of either a built-in or user defined class. In addition to properties, class defines functionality associated with data.


1 Answers

Here is a solution

$newObject = new stdClass;

$newObject->ERROR_CODE = 0;
$newObject->M_USER = new stdClass;
$newObject->M_USER->CREATE_DATE = "2018-05-09 13:57:49";

And so on.

like image 197
Krzysztof Janiszewski Avatar answered Sep 22 '22 01:09

Krzysztof Janiszewski