PHPackages                             cryonighter/object-column - 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. cryonighter/object-column

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

cryonighter/object-column
=========================

This package provides the object\_column() function, which works similarly to the array\_column() function of the standard library, but having the ability to work with objects

2.0.0(8mo ago)14.9k↓37.5%MITPHPPHP &gt;=8.1.0

Since May 10Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/cryonighter/object-column)[ Packagist](https://packagist.org/packages/cryonighter/object-column)[ Docs](https://github.com/cryonighter/object-column)[ RSS](/packages/cryonighter-object-column/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Object Column Function
======================

[](#object-column-function)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c4edac4e408cef513ad21176cd0137c3ca7277f486bbcaa2a27b7f0c3b09d7e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372796f6e6967687465722f6f626a6563742d636f6c756d6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cryonighter/object-column)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/f5a2ce367bb0ffe0e54e63c464171d55e8c1f0593b43ee395d2093a8946f73d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372796f6e6967687465722f6f626a6563742d636f6c756d6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cryonighter/object-column)

This package provides the **object\_column()** function, which works similarly to the [array\_column()](https://www.php.net/manual/en/function.array-column.php)function of the standard library, but having the ability to work with objects.

To search for columns in objects, both the public properties of these objects and the methods getColumnName() / hasColumnName() / isColumnName() / columnName() (in that exact order), as well as by the methods of the ArrayAccess interface.

Function **object\_column()** is fully backward compatible with [array\_column()](https://www.php.net/manual/en/function.array-column.php) and can work with regular arrays the same way.

In addition, the **object\_column()** function supports call chainings.

Highlights
----------

[](#highlights)

- Simple API
- Framework Agnostic
- Composer ready, [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/) compliant

System Requirements
-------------------

[](#system-requirements)

You need:

- **PHP &gt;= 8.1.0** but the latest stable version of PHP is recommended

Install
-------

[](#install)

Via Composer

```
$ composer require cryonighter/object-column
```

Usage
-----

[](#usage)

The function works as follows:

##### Example №1: simple access to public properties

[](#example-1-simple-access-to-public-properties)

```
use function Cryonighter\ObjectColumn\object_column;

$objects = [
    new class {
        public $foo = '123';
        public $bar = '456';
        public $baz = '789';
    },
    new class {
        public $foo = 'qwe';
        public $bar = 'asd';
        public $baz = 'zxc';
    },
];

$result = object_column($objects, 'foo', 'bar');
```

##### Example №2: chain of calls to getters

[](#example-2-chain-of-calls-to-getters)

```
use function Cryonighter\ObjectColumn\object_column;

$objects = [
    new class {
        public function getFoo(): object {
            return new class {
                public function baz(): string {
                    return '123';
                }
            };
        }
        public function getBar(): object {
            return new class {
                public function buz(): string {
                    return '456';
                }
            };
        }
    },
    new class {
        public function getFoo(): object {
            return new class {
                public function baz(): string {
                    return 'qwe';
                }
            };
        }
        public function getBar(): object {
            return new class {
                public function buz(): string {
                    return 'asd';
                }
            };
        }
    },
];

$result = object_column($objects, 'foo.baz', 'bar.buz');
```

##### Example №3: chain of calls to ArrayAccess objects

[](#example-3-chain-of-calls-to-arrayaccess-objects)

```
use function Cryonighter\ObjectColumn\object_column;

$objects = [
    new ArrayObject([
        'foo' => new ArrayObject(['baz' => '123']),
        'bar' => new ArrayObject(['buz' => '456']),
    ]),
    new ArrayObject([
        'foo' => new ArrayObject(['baz' => 'qwe']),
        'bar' => new ArrayObject(['buz' => 'asd']),
    ]),
];

$result = object_column($objects, 'foo.baz', 'bar.buz');
```

##### Result

[](#result)

In all cases, the result will be the same

```
[456 => '123', 'asd' => 'qwe']
```

### Callable arguments

[](#callable-arguments)

For more complex cases, you can pass your own handlers, which will be applied to all objects of the first nesting level. You will have to implement the handle of the following nesting levels yourself in your callback functions.

##### Example №4: callable arguments

[](#example-4-callable-arguments)

```
use function Cryonighter\ObjectColumn\object_column;

$objects = [
    new class {
        public function getFoo(): string {
            return '123';
        }
        public function getBar(): string {
            return '456';
        }
        public function getBaz(): string {
            return '789';
        }
    },
    new class {
        public function getFoo(): string {
            return 'qwe';
        }
        public function getBar(): string {
            return 'asd';
        }
        public function getBaz(): string {
            return 'zxc';
        }
    },
];

$result = object_column(
    $objects,
    fn(object $object): string => $object->getFoo() . '-' . $object->getBar(),
    fn(object $object): string => $object->getBar() . '-' . $object->getBaz(),
);
```

##### Result

[](#result-1)

```
[
    '456-789' => '123-456',
    'asd-zxc' => 'qwe-asd',
];
```

### Array indexing

[](#array-indexing)

Also, the function can be used to index an array, for this it is enough not to pass the first argument

##### Example №5: array indexing

[](#example-5-array-indexing)

```
use function Cryonighter\ObjectColumn\object_column;

$objects = [
    [
        'foo' => ['baz' => '123'],
        'bar' => ['buz' => '456'],
    ],
    [
        'foo' => ['baz' => 'qwe'],
        'bar' => ['buz' => 'asd'],
    ],
];

$result = object_column($objects, null, 'bar.buz');
// or
$result = object_column($objects, indexKey: 'bar.buz');
```

##### Result

[](#result-2)

```
[
    '456' => [
        'foo' => ['baz' => '123'],
        'bar' => ['buz' => '456'],
    ],
    'asd' => [
        'foo' => ['baz' => 'qwe'],
        'bar' => ['buz' => 'asd'],
    ],
];
```

For clarity, an example with a simple array is given, but it will work for all the cases listed above.

If no second or third argument is passed to the function, the original array will be returned. This operation is meaningless.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ php vendor/phpunit/phpunit/phpunit tests
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email `cryonighter@yandex.ru` instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andrey Reshetchenko](https://github.com/cryonighter)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance60

Regular maintenance activity

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~1579 days

Total

2

Last Release

254d ago

Major Versions

1.0.0 → 2.0.02025-09-06

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

2.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/640fd5daf250ddc27926b04a4fa74e2d8239c777475a783f155a6c9d47e1df78?d=identicon)[cryonighter](/maintainers/cryonighter)

---

Top Contributors

[![cryonighter](https://avatars.githubusercontent.com/u/20028293?v=4)](https://github.com/cryonighter "cryonighter (6 commits)")

---

Tags

objectiterablecolumnarray\_columnobject\_columniterable\_column

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cryonighter-object-column/health.svg)

```
[![Health](https://phpackages.com/badges/cryonighter-object-column/health.svg)](https://phpackages.com/packages/cryonighter-object-column)
```

###  Alternatives

[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/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.8k295.3M2.5k](/packages/symfony-property-access)[cuyz/valinor

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

1.5k9.2M108](/packages/cuyz-valinor)[kyslik/column-sortable

Package for handling column sorting in Laravel 6.x

6485.6M21](/packages/kyslik-column-sortable)[yzen.dev/plain-to-class

Class-transformer to transform your dataset into a structured object

16293.9k6](/packages/yzendev-plain-to-class)[pheme/yii2-toggle-column

Provides a toggle data column and action

27776.6k10](/packages/pheme-yii2-toggle-column)

PHPackages © 2026

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