What is the meaning of scalar here in php

Hi everyone, I am a pure developer. Now I am learning PHP. I am learning php objects and I am trying this code

<html> <head> </head> <body> <?php $obj=(object)'ciao'; echo $obj->scalar; ?> </body> </html> 

Here I want to know exactly what a scalar is? Why are we using it here?

+6
source share
2 answers

Convert to Object

If an object is converted to an object, it does not change. If a value of any other type is converted to an object, a new instance. The built-in class stdClass is created. If the value was NULL, the new instance will be empty. Arrays are converted to an object with properties named by keys, and corresponding values. For any other value, a member variable called scalar will contain the value.

 <?php $obj = (object) 'ciao'; echo $obj->scalar; // outputs 'ciao' ?> 

http://www.php.net/manual/en/language.types.object.php

+7
source

Here you convert ciao to object . When you do echo $obj->scalar; , you will get the result as ciao . Because a scalar is a member variable that contains this value.
For more information see this link: http://www.php.net/manual/en/language.types.object.php

0
source

All Articles