Home >Backend Development >PHP Problem >How to force type conversion to object in php

How to force type conversion to object in php

青灯夜游
青灯夜游Original
2021-05-27 18:09:443297browse

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'".

How to force type conversion to object in php

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) &#39;ciao&#39;;
var_dump($obj); 
var_dump($obj->scalar); 
?>

Output:

How to force type conversion to object in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn