phputil/rtti

A Run-Time Type Information extractor, useful for getting/setting private attributes from/to PHP objects.

1.4.1 2018-01-27 17:00 UTC

This package is auto-updated.

Last update: 2024-10-23 04:31:11 UTC


README

A Run-Time Type Information extractor, useful for getting or setting private and protected attributes from/to PHP objects.

We use semantic versioning. See our releases.

Classes:

Installation

composer require phputil/rtti

Example

Extracting all attributes from a class (even private or protected).

<?php
require_once 'vendor/autoload.php'; // or 'RTTI.php' when not using composer

use phputil\RTTI;

class User {
	private $name;
	function __construct( $n ) { $this->name = $n; }
	function getName() { return $this->name; }
}

// array( 'user' => 'Bob' )
var_dump( RTTI::getAttributes( new User( 'Bob' ), RTTI::allFlags() ) );
?>

License

MIT (c) Thiago Delgado Pinto