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
https://forums.phpfreaks.com/topic/282353-working-with-stdclass/
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.

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.