PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Aleksandar Zivanovic   PHP Hydrator Object   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example script
Class: PHP Hydrator Object
Inject values in object variables that are private
Author: By
Last change:
Date: 8 years ago
Size: 439 bytes
 

Contents

Class file image Download
<?php

require_once 'Hydrator.php';

/**
 * Example object
 */
class UserEntity
{
   
/** @var string */
   
private $firstName;

   
/** @var string */
   
private $lastName;

   
/** @var string */
   
public function getDisplayName()
    {
        return
"{$this->firstName} {$this->lastName}";
    }
}

$user = Hydrator::hydrate(new UserEntity(), [
   
'first_name' => 'John',
   
'last_name' => 'Smith',
]);

var_dump($user->getDisplayName());