PHP code example of sbwerewolf / json-serialize-trait

1. Go to this page and download the library: Download sbwerewolf/json-serialize-trait library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sbwerewolf / json-serialize-trait example snippets


use \SbWereWolf\JsonSerializable\JsonSerializeTrait;

class TraitTest implements JsonSerializable
{
/* Declaration of trait use */
    use \SbWereWolf\JsonSerializable\JsonSerializeTrait;
/* Declaration of class properties */
    private $privateProp = 'privateProp';
    protected $protectedProp = 'protected property value';
    public $publicProp = 'public class member';
}
/* Convert class-exemplar to JSON */
echo json_encode(new TraitTest(),JSON_PRETTY_PRINT);
/*
{
    "privateProp": "privateProp",
    "protectedProp": "protected property value",
    "publicProp": "public class member"
}
*/