PHPackages                             schnittstabil/get - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. schnittstabil/get

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

schnittstabil/get
=================

Get nested array values and object properties.

v3.3.0(7y ago)2113.0k211MITPHPPHP &gt;=7.1.0

Since Nov 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/schnittstabil/get)[ Packagist](https://packagist.org/packages/schnittstabil/get)[ Docs](https://github.com/schnittstabil/get)[ RSS](/packages/schnittstabil-get/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (22)Used By (11)

Get [![Build Status](https://camo.githubusercontent.com/741b87f30a1f9ad8f3cf229b52a62a2987cb1119dd90fc2169707decf9d2d94b/68747470733a2f2f7472617669732d63692e6f72672f7363686e69747473746162696c2f6765742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/schnittstabil/get) [![Coverage Status](https://camo.githubusercontent.com/faf11b40e0bf5ff6a8ebece4f78bc009a7906c113c69c99119cd800689264793/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7363686e69747473746162696c2f6765742f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/schnittstabil/get?branch=master)
====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#get--)

[![SensioLabsInsight](https://camo.githubusercontent.com/0a84f7af9a54e5fe613543f78ec941e3c457d2b5448a7f16661e5d599589c113/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63363737393862652d313433612d343332642d623131662d3439323130663433376133332f6269672e706e67)](https://insight.sensiolabs.com/projects/c67798be-143a-432d-b11f-49210f437a33)

> Get nested array values and object properties.

Install
-------

[](#install)

```
$ composer require schnittstabil/get

```

Usage
-----

[](#usage)

```
require __DIR__.'/vendor/autoload.php';

use Schnittstabil\Get;

echo 'Hello '.Get\value('name', $_REQUEST, 'John Doe');
echo 'Hello '.Get\valueOrFail('PHP_AUTH_USER', $_SERVER, 'User is not authenticated.');

echo 'user:     '.Get\env('DB_USER', 'root');
echo 'password: '.Get\envOrFail('DB_PASS', 'DB_PASS is not set');
```

API
---

[](#api)

### Schnittstabil\\Get\\value

[](#schnittstabilgetvalue)

```
/**
 * Return array values and object properties.
 *
 * @param string|int|mixed[] $path    the path
 * @param object|array|null  $target  the target
 * @param mixed              $default default value if $path is not valid
 *
 * @return mixed the value determined by `$path` or otherwise `$default`
 *
 * @SuppressWarnings(PHPMD.StaticAccess)
 */
function value($path, $target, $default = null)
{/**/}
```

```
use Schnittstabil\Get;

$array = ['zero', 'one', 'two'];
$array['foo'] = new \stdClass();
$array['foo']->bar = true;
$array['un.usual'] = true;

Get\value(1,              $array);  //=> 'one'
Get\value('1',            $array);  //=> 'one'
Get\value('foo.bar',      $array);  //=> true
Get\value(['foo', 'bar'], $array);  //=> true
Get\value(['un.usual'],   $array);  //=> true

// $default
Get\value('un.usual', $array);      //=> null
Get\value(3,          $array);      //=> null
Get\value(3,          $array, 42);  //=> 42
```

### Schnittstabil\\Get\\valueOrFail

[](#schnittstabilgetvalueorfail)

> Same as `Schnittstabil\Get\value`, but throws an `OutOfBoundsException`.

```
/**
 * Return array values and object properties.
 *
 * @param string|int|mixed[] $path    the path
 * @param object|array|null  $target  the target
 * @param mixed              $message exception message
 *
 * @throws \OutOfBoundsException if the `$path` does not determine a member of `$target`
 *
 * @return mixed the value determined by `$path`
 *
 * @SuppressWarnings(PHPMD.StaticAccess)
 */
function valueOrFail($path, $target, $message = null)
{/**/}
```

```
use Schnittstabil\Get;

Get\valueOrFail(3, $array);
//=> throws an OutOfBoundsException

Get\valueOrFail(3, $array, 'Error Message');
//=> throws a new OutOfBoundsException('Error Message')
```

### Schnittstabil\\Get\\typed

[](#schnittstabilgettyped)

```
/**
 * Converts a string value to a PHP typed value.
 *
 * @param mixed  $value
 * @return mixed
 */
function typed($value)
{/**/}
```

```
use Schnittstabil\Get;

Get\typed('42');
//=> int(42)

Get\typed('true');
Get\typed('yes');
Get\typed('on');
//=> bool(true)

Get\typed('false');
Get\typed('no');
Get\typed('off');
//=> bool(false)

/* escaping */
Get\typed('"true"');
Get\typed("'true'");
//=> string("true")
```

### Schnittstabil\\Get\\env

[](#schnittstabilgetenv)

```
/**
 * Gets the value of an environment variable.
 *
 * @param string $varname   the variable name
 * @param mixed  $default   default value if `$varname` is not valid
 * @param mixed  $typed     convert environment value to a PHP typed value
 * @param bool   $localOnly return only values of local environment variables
 *
 * @return mixed the environment value determined by `$varname` or otherwise `$default`
 */
function env($varname, $default = null, $typed = true, $localOnly = false)
{/**/}
```

### Schnittstabil\\Get\\envOrFail

[](#schnittstabilgetenvorfail)

```
/**
 * Gets the value of an environment variable.
 *
 * @param string $varname   the variable name
 * @param mixed  $message   exception message
 * @param mixed  $typed     convert environment value to a PHP typed value
 * @param bool   $localOnly return only values of local environment variables
 *
 * @throws OutOfBoundsException if the `$varname` does not determine an environment value
 *
 * @return mixed the environment value determined by `$varname`
 */
function envOrFail($varname, $message = null, $typed = true, $localOnly = false)
{/**/}
```

License
-------

[](#license)

MIT © [Michael Mayer](http://schnittstabil.de)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 97.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~115 days

Total

21

Last Release

2817d ago

Major Versions

v1.7.0 → v2.0.02016-04-03

v2.2.0 → v3.0.02017-05-26

PHP version history (2 changes)v1.6.3PHP &gt;=5.6.0

v3.2.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6059032?v=4)[Michael Mayer](/maintainers/schnittstabil)[@schnittstabil](https://github.com/schnittstabil)

---

Top Contributors

[![schnittstabil](https://avatars.githubusercontent.com/u/6059032?v=4)](https://github.com/schnittstabil "schnittstabil (44 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

arraynestedobjectgetvaluenullcoalescing

### Embed Badge

![Health badge](/badges/schnittstabil-get/health.svg)

```
[![Health](https://phpackages.com/badges/schnittstabil-get/health.svg)](https://phpackages.com/packages/schnittstabil-get)
```

###  Alternatives

[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[jasny/dotkey

Dot notation access for objects and arrays

14219.5k6](/packages/jasny-dotkey)[michaldudek/foundation

A set of useful PHP classes.

13111.9k13](/packages/michaldudek-foundation)[peridot-php/object-path

A string syntax to fetch values from array and object hierarchies

1053.6k1](/packages/peridot-php-object-path)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
