PHP code example of ucscode / object-reflector

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

    

ucscode / object-reflector example snippets


use Ucscode\ObjectReflector\ObjectReflector;

$reflector = new ObjectReflector($object);

// Assuming "id" and "passwordHash" are private or protected properties
$reflector
    ->set('id', 123)
    ->set('passwordHash', $newHash)
    ->call('updateTimestamps'); // Assuming "updateTimestamps" is a private or protected method


$reflector
    ->reflect('invoice') // Assuming "invoice" is a private object
    ->reflect('client') // Assuming "client" is a private object inside "invoice"
    ->set('due', '$23.00'); // will set "object.invoice.client.due = $23.00"


// Variadic
$reflector->call('logAction', 'User Update', 1);

// Array-based (useful for dynamic data)
$reflector->callArray('syncStatus', [
    'status' => 'active', 
    'notified' => true
]);