Transformation example of a class in php
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!