PHPackages                             milo/alias-expander - 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. milo/alias-expander

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

milo/alias-expander
===================

Runtime alias expanding to fully qualified class name.

v1.0.0(12y ago)228BSD-3-ClausePHPPHP &gt;=5.3.0

Since Jul 22Pushed 12y ago2 watchersCompare

[ Source](https://github.com/milo/alias-expander)[ Packagist](https://packagist.org/packages/milo/alias-expander)[ RSS](/packages/milo-alias-expander/feed)WikiDiscussions master Synced 4w ago

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

[AliasExpander](https://github.com/milo/alias-expander/blob/master/AliasExpander.php)
=====================================================================================

[](#aliasexpander)

It is a tool for run-time class alias expanding to its fully qualified name. In brief, it is a workaround for missing `::class` constant from PHP 5.5 in PHP 5.3+ and a helper for annotations processing.

```
# An ordinary 'use' usage in namespaced code. But how to expand the alias to full class name?
use Other\Lib as OL;

# in PHP 5.5+
echo OL::class;  // 'Other\Lib'

# in PHP 5.3+
echo Alias::expand('OL');  // 'Other\Lib'

# If the static call is too long for you, wrap it in own function. It will be easy to replace
# when upgrade to PHP 5.5.
function aliasFqn($alias) {
	return \Milo\Alias::expand($alias, 1);
}

# Due to performance, it is good to set writable directory for caching.
Alias::getExpander()->setCacheDir('/path/to/tmp');

# If you want to be strict and ensure that alias expands only to defined class name,
# set exists checking. This is a debugging advantage against to ::class in PHP 5.5.
Alias::getExpander()->setExistsCheck(TRUE);
# or
Alias::getExpander()->setExistsCheck(E_USER_WARNING);

# Expanding an alias in explicitly specified file and line context is useful
# for annotations processing.
$method = new ReflectionMethod($object, 'method');
Alias::expandExplicit('NS\Alias', $method->getFileName(), $method->getStartLine());

# The Milo\Alias class is only a static wrapper for the Milo\AliasExpander object.
# You can use a non-static variation in the same way.
$expander = new Milo\AliasExpander;
$expander->expand('OL');
$expander->expandExplicit('OL', $file, $line);
$expander->setCacheDir('/path/to/tmp');
...
```

If you know the [Nette Framework](http://nette.org), there is a [prepared](https://github.com/milo/alias-expander/blob/master/Nette/AliasExpander.php) version of expander for using with Nette\\Cache.

```
$storage = new Nette\Caching\Storages\FileStorage('/path/to/tmp');
$expander = new Milo\Nette\AliasExpander($storage);
```

There are some limitations:

- One line code like `namespace First; AliasExpander::expand('Foo'); namespace Second;` may leads to wrong expanding. It is not so easy to implement it because PHP tokenizer and debug\_backtrace() provides only line number, but not the column. This can be a problem in minified code.
- Keywords `self`, `static` and `parent` are not expanded as in PHP 5.5, but this can be easily solved by `__CLASS__`, `get_called_class()` and `get_parent_class()` instead of AliasExpander using.

Licence
=======

[](#licence)

You may use all files under the terms of the New BSD Licence, or the GNU Public Licence (GPL) version 2 or 3, or the MIT Licence.

Tests
=====

[](#tests)

The AliasExpander tests are written for [Nette Tester](https://github.com/nette/tester). Two steps are required to run them:

```
# Download the Tester tool
composer.phar update --dev

# Run the tests
vendor/bin/tester tests
```

---

[![Build Status](https://camo.githubusercontent.com/122a111bc5c28bbb0d2929775cd37740334da43de046976ab086d4310efa7fea/68747470733a2f2f7472617669732d63692e6f72672f6d696c6f2f616c6961732d657870616e6465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/milo/alias-expander)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4727d ago

### Community

Maintainers

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

---

Top Contributors

[![milo](https://avatars.githubusercontent.com/u/439140?v=4)](https://github.com/milo "milo (20 commits)")

### Embed Badge

![Health badge](/badges/milo-alias-expander/health.svg)

```
[![Health](https://phpackages.com/badges/milo-alias-expander/health.svg)](https://phpackages.com/packages/milo-alias-expander)
```

###  Alternatives

[yassi/nova-nested-form

A Laravel Nova package that allows you to create/update/delete nested related fields from a parent form.

239505.2k](/packages/yassi-nova-nested-form)

PHPackages © 2026

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