PHP code example of keven / hydrate

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

    

keven / hydrate example snippets




$obj = new stdClass;
\Keven\hydrate(array('foo' => 'bar'), $obj);
echo $obj->foo; // "bar"



$car = new Car(array(
    'engine' => 'V8',
    'color'  => 'red',
    'brand'  => 'Chevrolet',
));
echo $car->getColor(); // "red"

class Car
{
    private $engine, $color, $brand;

    public function __construct($args)
    {
        hydrate($args);
    }

    public function getEngine()
    {
        return $this->engine;
    }

    public function getColor()
    {
        return $this->color;
    }

    public function getBrand()
    {
        return $this->brand;
    }
}