rickwong/trespass

Access and chain object properties and methods in a safe manner.


Keywords
operator, object, proxy, properties, deep, Chain, property, propagation, null, optional, es6, tresspass, undefined, existential, access, array, chaining, methods, safe, trespass
License
BSD-3-Clause

Documentation

trespass-php

Tired of isset() and ?: safety-guards? Access object properties and chain methods in a safe manner.

Installation

composer require rickwong/trespass

Usage

Simple:

use function Trespass\t;

t(null)->foo->•; // access undefined properties 
t(false)->bar()->•; // call undefined methods
t([])->bar()['bat']->baz->•; // call undefined methods and then access undefined properties

Custom terminator:

$t = Trespass\createWrapper('__value');
$t($foo)->bar->__value; 

Requirements

PHP 5.6+.

Community

Let's start one together! After you ★ this project, follow me @rygu on Twitter.

License

BSD 3-Clause license. Copyright © 2017, Rick Wong. All rights reserved.