News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Johannes Schluter's Blog:
Jason, let me help you!
June 04, 2010 @ 10:02:15

In a new post to his blog Johannes Schluter looks at a helpful new inclusion into the latest versions of the PHP trunk - a new JSON serialization interface included in the core.

For many PHP objects the JSON-representation of the data is a bit more complex.for instance what about private properties or maybe you want to calculate some inner values? - In PHP 5.3 you were on your own. but thanks to Sara there's hope in sight: the new interface JsonSerializable. Classes implementing this interface have to provide a method jsonSerialize() which will be called by json_encode() and has to return a JSON-compatible representation of the data by doing whatever you want.

He gives two examples of this new feature in action - a simple one that just spits out some basic JSON as a result of the output of a class and the other that's a bit more technical, involving multiple class isntances, a stdClass and a normal array.

1 comment voice your opinion now!
json jsonserializable encode interface implements


blog comments powered by Disqus

Similar Posts

Slawek Lukasiewicz's Blog: New Features in PHP 5.4 - JSON Extension & header_register_callback

Federico Cargnelutti's Blog: An Alternative to Zend_Controller: The Model

Chris Hartjes' Blog: Doing RADAR in CakePHP

phpRiot.com: Combining PHP, JSON and jQuery Screencast

SitePoint PHP Blog: Composer Cheatsheet


Community Events





Don't see your event here?
Let us know!


series version update mvc framework interview laravel composer language release opinion voicesoftheelephpant community symfony package tool podcast introduction security library

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework