PHP code example of northern / serializer

1. Go to this page and download the library: Download northern/serializer 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/ */

    

northern / serializer example snippets


use Northern\Serializer\Serializer;

$serializer = new Serializer();

$array = $serializer->toArray( $someObject );

use Northern\Serializer\Annotation as Serialize;

class SomeClass {

  /** @Serialize\Int */
  protected $myProperty = 123;

}

Array(
  [myProperty] => 123
)

use Northern\Serializer\Annotation as Serialize;

class SomeClass {

  /** @Serialize\Int(name="myValue") */
  public function getMyValue()
  {
    return 123;
  }

}

Array(
  [myValue] => 123
)

class SomeClass {

  /** @Serialize\Bool */
  public function isValid()
  {
    return true;
  }

}

Array(
  [isValid] => 1
)

class BarClass {
	
	/** @Serialize\Int */
	protected $barValue = 123;

}

class FooClass {

  /** @Serialize\Object */
  protected $bar;

  public function __construct()
  {
    $this->bar = new BarClass();
  }

}