How to force type conversion to object in php

青灯夜游
Release: 2023-03-10 06:34:01
Original
3192 people have browsed it

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); 
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!