PHP code example of felixdorn / property-accessor
1. Go to this page and download the library: Download felixdorn/property-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/ */
felixdorn / property-accessor example snippets
use function \Felix\PropertyAccessor\access;
class Book {
protected string $name = 'Harry Potter';
protected int $isbn = 44081224;
}
$object = new Book();
access($object, 'isbn'); // returns 44081224
// Properties are injected based on the parameter name passed to the function.
access($object, function ($isbn, $name) {
return $isbn . ' - ' . $name;
}); // returns '44081124 - Harry Potter'
access($object, ['isbn', 'name']); // returns ['isbn' => 44081224, 'name' => 'Harry Potter']