In PHP, you can add the target type "(object)" enclosed in parentheses before the variable or value to be converted to perform forced type conversion to force the variable or value to the object type, for example "(object) 'ciao'".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
PHP forced type conversion--in The variable to be converted is preceded by the target type enclosed in parentheses
The PHP data types allowed for conversion are:
(int), (integer) : Convert to integer
(float), (double), (real): Convert to floating point type
(string): Convert Into string
(bool), (boolean): Convert to Boolean type
(array): Convert to array
(object): Convert to object
Example: Cast to object
<?php $obj = (object) 'ciao'; var_dump($obj); var_dump($obj->scalar); ?>
Output:
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to force type conversion to object in php. For more information, please follow other related articles on the PHP Chinese website!