Get the App
SLTechnology News&Howtos  ›  Development  › 

Transformation example of a class in php

Shulou Source: shulou.com Published: 2022-06-01 04:35:16 09月22日 Update

This article mainly introduces the php class conversion examples, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Class (class) conversion

Here is a class for PHP:

Class Foo {const ERROR_CODE = '404; public $public_ex =' this is public'; private $private_ex = 'this is privatekeeper; protected $protected_ex =' this should be protected'; public function getErrorCode () {return self::ERROR_CODE;}}

Now, perform a json transformation on an instance of this class:

$foo = new Foo;$foo_json = json_encode ($foo); echo $foo_json

The output is

{"public_ex": "this is public"}

As you can see, everything else (constants, private variables, methods, and so on) is lost except public variables (public).

Thank you for reading this article carefully. I hope the article "sample conversion of classes in php" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles examples variables things values interests at the same time examples constants methods more friends knowledge results editing industry information information channels channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei vpn macOS Redmi