PHP code example of polidog / object-access

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

    

polidog / object-access example snippets


class User {

    /**
     * @var int
     */
    private $id;

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

    /**
     * Sample constructor.
     * @param int $id
     * @param string $name
     */
    public function __construct(int $id, string $name)
    {
        $this->id = $id;
        $this->name = $name;
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

}

$user = new User(120,'test-user');
$accessor = \Polidog\ObjectAccess\ObjectAccess::createAccessor();
$accessor->setter($user, 'name', 'change-name-user');

var_dump($user->getName()); // change-name-user