Jump to content

Working with stdClass


eldan88

Recommended Posts

Hey guys. I have another question. I am learning about using stdClass, I read through the PHP documentation, and don't understand couple of things.

 

  1. What does the documentation mean when they say "If an object is converted to an object, it is not modified"?
  2. What is the point of of a scaler? What is a scaler
  3. What is the purpose of having a nested array if you when defining keys and values in a std object . E.g....
    $obj = (object) array (
    "hello" => 'World',
    "nested" => array("key"=>"value"),);
    

I know these questions might sound a little amuterish, but I am just trying to get the hang of using objects in PHP. Thank you for you help!

Link to comment
Share on other sites

0. There's nothing to learn about stdClass. There's stuff to learn about objects in general.

1. Casting an object to an object doesn't change anything.

2. A scalar is a very simple data type; you can use them as array keys and they're easy to store basically anywhere. Numbers and strings. Arrays, objects, and resources are not scalar.

3. $obj->nested is an array. You're doing that in the code because you have some reason for doing that.

Link to comment
Share on other sites

understand that casting to an object doesn't change anything, but I don't understand how that works

Typecasting is just causes one value to be changed from one type to another type. If the value is already in the proper type, then it's a no-op (ie, nothing happens, the value is returned as-is).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.