Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of scalar here in php

Tags:

php

Hello everyone I am net developer.Now I am learning PHP. I am studying about the php objects and I try this code

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

Here I want to know what is the scalar exactly? Why We are using it here?

like image 420
Azad Chouhan Avatar asked Jan 09 '14 04:01

Azad Chouhan


1 Answers

Converting to object

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

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

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

like image 80
Robert Harvey Avatar answered Sep 30 '22 08:09

Robert Harvey