PHP code example of piano / accessor

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

    

piano / accessor example snippets




namespace App;

class User
{
    private $name;
    private $age;
    private $createdAt;

    public function setName($name)
    {
        $this->name = $name;
    }

    public function setAge($age)
    {
        $this->age = (int) $age;
    }

    public function setCreatedAt(\DateTime $createdAt)
    {
        $this->createdAt = $createdAt;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getAge()
    {
        return (int) $this->age;
    }

    public function getCreatedAt()
    {
        return $this->createdAt;
    }
}



namespace App;

class User
{
    use \Piano\AccessorTrait;

    /**
     * @set
     * @get
     */
    private $name;

    /**
     * @set int
     * @get int
     */
    private $age;

    /**
     * @set \DateTime
     * @get
     */
    private $createdAt;
}