PHPackages                             florianeckerstorfer/get-from - 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. florianeckerstorfer/get-from

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

florianeckerstorfer/get-from
============================

Functions for object traversal.

v1.0.0(12y ago)066MITPHPPHP &gt;=5.4

Since Mar 9Pushed 12y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

get-from
========

[](#get-from)

Function to retrieve values from objects without painfully checking if the value `isset`. Inspired by and ported from the great [get-in](https://github.com/igorw/get-in) library for arrays from Igor Wiedler.

For example, to access a nested property `->foo->bar->baz`, you must do something like this:

```
$baz = (isset($data->foo->bar->baz)) ? $data->foo->bar->baz : null;
```

Enough already! get-from provides a better way:

```
$baz = florianec\get_from($data, ['foo', 'bar', 'baz']);
```

`get_from` is specially handy when dealing with deeply nested objects like those generated by [SimpleXML](http://at2.php.net/manual/en/book.simplexml.php).

[![Build Status](https://camo.githubusercontent.com/52894c2be7b3b274a578456efa35d5f0548e4109eb725836488e16e34334a1c7/68747470733a2f2f7472617669732d63692e6f72672f666c6f7269616e65636b657273746f726665722f6765742d66726f6d2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/florianeckerstorfer/get-from)

Installation
------------

[](#installation)

Through composer:

```
$ composer require florianeckerstorfer/get-from:~1.0
```

Usage
-----

[](#usage)

### get\_in

[](#get_in)

Retrieve value from a nested structure using a list of keys:

```
$data = new \stdClass();
$data->foo = new \stdClass();
$data->foo->bar = new \stdClass();
$data->foo->bar->baz = 'oof';

$name = florianec\get_from($data, ['foo', 'bar', 'baz']);
//= 'oof'
```

Non existent keys return `null`:

```
$data = new \stdClass();
$data->foo = 'bar';

$baz = florianec\get_from($data, ['baz']);
//= null
```

You can provide a default value that will be used instead of `null`:

```
$data = new \stdClass();
$data->foo = 'bar';

$baz = florianec\get_from($data, ['baz'], 'qux');
//= 'qux'
```

Changelog
---------

[](#changelog)

### Version 1.0 (9 March 2014)

[](#version-10-9-march-2014)

- Initial release

Inspiration
-----------

[](#inspiration)

This library is a complete ripoff of Igor Wiedler's [get-in](https://github.com/igorw/get-in) library. Even this README file is largely inspired by Igors work. Scandalous.

I created this library/function when I wanted to clean up the code dealing with XML from an external web service and I realised that `get-in` only works for arrays and not for objects.

Author
------

[](#author)

- [Florian Eckerstorfer](http://florian.ec) ([Twitter](http://twitter.com/Florian_), [App.net](http://app.net/florian))

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2014 Florian eckerstorfer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

4496d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a80f9fc61cd3a7d7779e8f120b458ca4d18fdd885d719bb77d3379b96bf714d9?d=identicon)[florianeckerstorfer](/maintainers/florianeckerstorfer)

---

Tags

objecttraversal

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k878.9M209](/packages/myclabs-deep-copy)[symfony/property-access

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

2.8k309.5M3.0k](/packages/symfony-property-access)[cuyz/valinor

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

1.5k11.7M157](/packages/cuyz-valinor)[yzen.dev/plain-to-class

Class-transformer to transform your dataset into a structured object

162101.6k6](/packages/yzendev-plain-to-class)[kdyby/strict-objects

Simple trait to make your class strict, when calling or accessing undefined member (property or method).

311.7M18](/packages/kdyby-strict-objects)[peridot-php/object-path

A string syntax to fetch values from array and object hierarchies

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

PHPackages © 2026

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