eldan88 Posted September 22, 2013 Share Posted September 22, 2013 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. What does the documentation mean when they say "If an object is converted to an object, it is not modified"? What is the point of of a scaler? What is a scaler 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! Quote Link to comment https://forums.phpfreaks.com/topic/282353-working-with-stdclass/ Share on other sites More sharing options...
requinix Posted September 22, 2013 Share Posted September 22, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282353-working-with-stdclass/#findComment-1450621 Share on other sites More sharing options...
eldan88 Posted September 23, 2013 Author Share Posted September 23, 2013 Thanks for the reply. I understand, everything you pointed and understand that casting to an object doesn't change anything, but I don't understand how that works. Would you please show me small example? Quote Link to comment https://forums.phpfreaks.com/topic/282353-working-with-stdclass/#findComment-1450748 Share on other sites More sharing options...
kicken Posted September 23, 2013 Share Posted September 23, 2013 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). Quote Link to comment https://forums.phpfreaks.com/topic/282353-working-with-stdclass/#findComment-1450749 Share on other sites More sharing options...
eldan88 Posted September 26, 2013 Author Share Posted September 26, 2013 Okay got it Kicken. Thanks for the explanation. Quote Link to comment https://forums.phpfreaks.com/topic/282353-working-with-stdclass/#findComment-1451329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.