PHPackages                             imliam/php-modifiers - 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. imliam/php-modifiers

ActiveLibrary

imliam/php-modifiers
====================

Apply optional modifiers to PHP functions

v1.1.0(1y ago)17MITPHPPHP ^8.0

Since Apr 20Pushed 1y ago1 watchersCompare

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

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

PHP Modifiers
=============

[](#php-modifiers)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3632c61653f22a5f41aa6d0cf653cf697f9127ad34e503f07841b4a8b750f2b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d6c69616d2f7068702d6d6f646966696572732e737667)](https://packagist.org/packages/imliam/php-modifiers)[![Code Quality](https://camo.githubusercontent.com/0df47d9caa620c59b877e05f32e4bcf807b8f32952b0f39858045e1ad63e2f37/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f696d6c69616d2f7068702d6d6f646966696572732e737667)](https://camo.githubusercontent.com/0df47d9caa620c59b877e05f32e4bcf807b8f32952b0f39858045e1ad63e2f37/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f696d6c69616d2f7068702d6d6f646966696572732e737667)[![Total Downloads](https://camo.githubusercontent.com/19dedc35b29ae95e2e7b564bf77ad3f32873f8e817abf0f403f8e843ea1bf5ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696d6c69616d2f7068702d6d6f646966696572732e737667)](https://packagist.org/packages/imliam/php-modifiers)[![License](https://camo.githubusercontent.com/c2a4e0049f7ff7c9de34b5e2672c4ae4f3064903bb6c27441d97fe6c5a44a8b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d6c69616d2f7068702d6d6f646966696572732e737667)](LICENSE.md)

Adds the ability to apply a range of optional modifiers `! @ ~ + -` when calling your class methods to augment them with a unique syntax.

For example, we may have a class where each of the following may do different things:

```
Slack::say('Hello world'); // 'Hello world'
!Slack::say('Hello world'); // 'HELLO WORLD'
@Slack::say('Hello world'); // 'Someone said "Hello world"'
@!Slack::say('Hello world'); // 'Someone said "HELLO WORLD"'
```

- [PHP Modifiers](#php-modifiers)
    - [💾 Installation](#-installation)
    - [📝 Usage](#-usage)
        - [Global Functions](#global-functions)
    - [The Modifiers](#the-modifiers)
        - [`!` Exclamation Mark](#-exclamation-mark)
        - [`+` Plus Symbol](#-plus-symbol)
        - [`-` Minus Symbol](#--minus-symbol)
        - [`~` Tilde Symbol](#-tilde-symbol)
        - [`@` "At" Symbol](#-at-symbol)
    - [How It Works](#how-it-works)
    - [✅ Testing](#-testing)
    - [🔖 Changelog](#-changelog)
    - [⬆️ Upgrading](#%EF%B8%8F-upgrading)
    - [🎉 Contributing](#-contributing)
        - [🔒 Security](#-security)
    - [👷 Credits](#-credits)
    - [♻️ License](#%EF%B8%8F-license)

💾 Installation
--------------

[](#-installation)

You can install the package with [Composer](https://getcomposer.org/) using the following command:

```
composer require imliam/php-modifiers:^1.0.0
```

📝 Usage
-------

[](#-usage)

This package's functionality is exposed through the `HasModifiers` trait, which can be applied to a class:

```
class Example
{
    use HasModifiers;
}
```

With the trait applied to the class, you must also define the class methods that can have modifiers used. This can be done by setting a static `$modifierAliases` property on the class.

This property should be an array that contains pairs of the class and method name that can be used.

For example if we wanted the `say` method on the current class to be able to use modifiers:

```
public static $modifierAliases = [
    [self::class, 'say'],
];
```

With this set up, inside the method we can now check if certain modifiers have been used by calling the `static::hasModifier()` method:

```
public static function say($string)
{
    if (static::hasModifier('!')) {
        echo strtoupper($string);
        return;
    }

    echo $string;
}
```

With it all in place, we can now call our method either with or without the modifier to get the desired behaviour:

```
Example::say('Hello world'); // 'Hello world'
!Example::say('Hello world'); // 'HELLO WORLD'
```

### Global Functions

[](#global-functions)

If we wanted to register a global function that can accept modifiers, we can use one to call our class method, as well as registering it as an alias by adding it to the `$modifierAliases` property.

```
function say($string)
{
    return Example::say($string);
}

Example::$modifierAliases[] = 'say';
```

The function will now work in the same way as before:

```
say('Hello world'); // 'Hello world'
!say('Hello world'); // 'HELLO WORLD'
```

The Modifiers
-------------

[](#the-modifiers)

There are five modifiers available to use. It is very important to note that as they are all also regular operators in PHP, each of them have their own quirks that might change the expected behaviour and return values of the methods.

Using them

Due to this, it would make sense to only use these modifiers on void functions that are not expected to return anything of use.

### `!` Exclamation Mark

[](#-exclamation-mark)

**Do not use the return value with this modifier.**

The exclamation mark is a [logical operator](https://www.php.net/manual/en/language.operators.logical.php) in PHP that negates the value to the opposite boolean. This means that any truthy value that is returned will be false, and any falsy value returned will be true.

### `+` Plus Symbol

[](#-plus-symbol)

**Do not use the return value with this modifier.**

The plus symbol is an identity [arithmetic operator](https://www.php.net/manual/en/language.operators.arithmetic.php) in PHP. Used as a modifier, it will attempt to cast the return value to an integer or float.

### `-` Minus Symbol

[](#--minus-symbol)

**Do not use the return value with this modifier.**

The plus symbol is a negative identity [arithmetic operator](https://www.php.net/manual/en/language.operators.arithmetic.php) in PHP. Used as a modifier, it will attempt to cast the return value to an integer or float.

### `~` Tilde Symbol

[](#-tilde-symbol)

**Do not use the return value with this modifier.**

The tilde symbol is a [bitwise operator](https://www.php.net/manual/en/language.operators.bitwise.php) in PHP. However, as the operator itself performs a bitwise operation, any method using this operator **must return an integer value**, or something that can be cast to one.

### `@` "At" Symbol

[](#-at-symbol)

**You can use the return value with this modifier.**

The "at" symbol is an [error suppression operator](https://www.php.net/manual/en/language.operators.errorcontrol.php) in PHP that hides and ignores any errors that occur in the proceeding statement - meaning errors that might be within your method will be unexpectedly ignored.

However, this is the only one of the operators that does not alter the return value of the method.

```
public static function hasSomething()
{
    if (static::hasModifier('@')) {
        trigger_error("An error should occur here, but it gets ignored…");

        return 'A modified value…';
    }

    return 'A non-modified value…';
}

echo Example::hasSomething(); // 'A non-modified value…'
echo @Example::hasSomething(); // 'A modified value…'
```

How It Works
------------

[](#how-it-works)

✨ Magic ✨

The modifier functionality works by taking a stack trace at the point the method was called, finding the point aliased method was called further up in the stack trace. Once these aliases are found, the file is read as a string and the [PHP source tokens are parsed](https://php.net/manual/en/function.token-get-all.php) to find the operators that came before it.

This was originally seen in the [Kint](https://github.com/kint-php/kint) package as a way to quickly augment how your variables are displayed while debugging. Because it was designed for this environment, great performance was not a huge concern. Following stack traces and parsing source code are generally *slow* operations in PHP, so take it with a grain of salt and don't abuse it in large production applications.

Check the source code to see how it works in more depth. This package is a stripped down version of Kint's implementation that fits in a couple of small source files.

✅ Testing
---------

[](#-testing)

```
composer test
```

🔖 Changelog
-----------

[](#-changelog)

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

⬆️ Upgrading
------------

[](#️-upgrading)

Please see the [upgrading file](UPGRADING.md) for details on upgrading from previous versions.

🎉 Contributing
--------------

[](#-contributing)

Please see the [contributing file](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md) for details on contributing to the project.

### 🔒 Security

[](#-security)

If you discover any security related issues, please email  instead of using the issue tracker.

👷 Credits
---------

[](#-credits)

- [Liam Hammett](https://github.com/imliam)
- [Kint](https://github.com/kint-php/kint) and all of its contributors for the implementation
- [All Contributors](../../contributors)

♻️ License
----------

[](#️-license)

The MIT License (MIT). Please see the [license file](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance45

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

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

Total

2

Last Release

426d ago

PHP version history (2 changes)v1.0.0PHP ^7.2

v1.1.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e8a14b9f997cf85aacea7d39da9dc33c38cc05fe03360578327ea9bcb25f4d9?d=identicon)[ImLiam](/maintainers/ImLiam)

---

Top Contributors

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

---

Tags

imliamphp-modifiers

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/imliam-php-modifiers/health.svg)

```
[![Health](https://phpackages.com/badges/imliam-php-modifiers/health.svg)](https://phpackages.com/packages/imliam-php-modifiers)
```

###  Alternatives

[imliam/laravel-env-set-command

Set a .env file variable from the command line

118352.4k10](/packages/imliam-laravel-env-set-command)[imliam/laravel-blade-helper

An easier way to define custom Blade directives.

185121.0k](/packages/imliam-laravel-blade-helper)[imliam/laravel-throttle-simultaneous-requests

Throttle the current user's requests based on how many requests are currently being executed.

4623.0k](/packages/imliam-laravel-throttle-simultaneous-requests)[imliam/php-unique-gmail-address

Ensure that a Gmail address is unique

914.9k](/packages/imliam-php-unique-gmail-address)

PHPackages © 2026

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