PHPackages                             withinboredom/nameof - 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. withinboredom/nameof

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

withinboredom/nameof
====================

Get the name of anything

v0.2.1(3y ago)32.1k↓88.9%MITPHP

Since Apr 23Pushed 3y ago2 watchersCompare

[ Source](https://github.com/withinboredom/nameof)[ Packagist](https://packagist.org/packages/withinboredom/nameof)[ RSS](/packages/withinboredom-nameof/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

PHP: NameOf
===========

[](#php-nameof)

This is a library to get the name of a variable. Some example usages:

```
enum Foo {
    case Bar;
    case Baz;
}

$arr = [];
$arr[nameof(Foo::Bar)] = 1; // resolves to 'Bar'
```

For compact:

```
$var = 1;
$bar = 2;
echo (compact(nameof($var), nameof($bar))); // ['var' => 1, 'bar' => 2]
```

Why?
----

[](#why)

This is useful when you want to use the name of a variable in a string, but want to retain easier refactoring. For example, normally when using compact you end up with a 'magic string' that references a variable name. However, this can be a problem if you want to refactor the variable name, as you have to change the string as well. This library allows you to use the nameof function to get the name of the variable, and then use that in the compact function. You can also use this for enum keys, and other places where you want to use the name of a variable.

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

[](#installation)

```
composer require withinboredom/nameof
```

Example output
--------------

[](#example-output)

Here are some examples and their output, note that no error will be thrown if you pass it weird things because it isn't doing any parsing to make sure you are only passing sensible things.

```
echo nameof(1); // 1
echo nameof($myCallback(...)); // myCallback
echo nameof($x->prop); // prop
echo nameof($x->prop->fun(...)) // fun
```

###  Health Score

24

—

LowBetter than 30% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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 ~5 days

Total

3

Last Release

1201d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1883296?v=4)[Rob Landers](/maintainers/withinboredom)[@withinboredom](https://github.com/withinboredom)

---

Top Contributors

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

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/withinboredom-nameof/health.svg)

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

###  Alternatives

[vaimo/module-admin-auto-login

Provides automatic admin login on Magento projects; Useful addition when working with a project locally (should be used only as require-dev)

2140.7k](/packages/vaimo-module-admin-auto-login)[kakuilan/php-helper

k`s php helper/library/utils

304.9k3](/packages/kakuilan-php-helper)[humanmade/foundry

Foundry is an experimental approach to custom tables in WordPress.

152.4k6](/packages/humanmade-foundry)

PHPackages © 2026

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