PHPackages                             code-distortion/staticall - 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. code-distortion/staticall

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

code-distortion/staticall
=========================

Run class methods both statically and non-statically

0.4.1(5mo ago)013.5k1MITPHPPHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\* | 8.5.\*CI passing

Since Jan 15Pushed 5mo ago1 watchersCompare

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

READMEChangelog (8)Dependencies (5)Versions (9)Used By (1)

Staticall
=========

[](#staticall)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bf4ac8733d279870a4dad1db301a266f5fc62eff2886e8f5ca870ff2d6f82339/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64652d646973746f7274696f6e2f737461746963616c6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/code-distortion/staticall)[![PHP Version](https://camo.githubusercontent.com/7377a12d33082dcc66e398bcdfe01550146ac043eef13190ae9c5c99018ee3a0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e30253230746f253230382e352d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7377a12d33082dcc66e398bcdfe01550146ac043eef13190ae9c5c99018ee3a0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e30253230746f253230382e352d626c75653f7374796c653d666c61742d737175617265)[![GitHub Workflow Status](https://camo.githubusercontent.com/089eb63067d5f9460fad148ac27110b737963d23dd87652411f058133f462288/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64652d646973746f7274696f6e2f737461746963616c6c2f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/code-distortion/staticall/actions)[![Buy The World a Tree](https://camo.githubusercontent.com/dc3f77a9b22c3bc83c7b7d863bf138a7ca3418f1826b0b16d073d0aa87c16bc4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74726565776172652d2546302539462538432542332d6c69676874677265656e3f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/code-distortion/staticall)[![Contributor Covenant](https://camo.githubusercontent.com/902d296a65b2997bada7e7717fd929d9177f3bd95414cbb5ea2ed843c680f314/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e7472696275746f72253230636f76656e616e742d76322e3125323061646f707465642d6666363962342e7376673f7374796c653d666c61742d737175617265)](.github/CODE_OF_CONDUCT.md)

***code-distortion/staticall*** is a package for that lets you call methods statically and non-statically.

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

[](#installation)

Install the package via composer:

```
composer require code-distortion/staticall
```

Usage
-----

[](#usage)

- Include the `Staticall` trait in your class
- Add methods to your class with the prefix `staticall`

```
use CodeDistortion\Staticall\Staticall; // recipient('Bob', 'bob@test.com')->send();
```

> ***Note:*** Because Staticall calls your constructor automatically, the constructor must not have any required parameters.

> ***Note:*** Staticall makes the methods it finds accessible *publicly*.

### Detecting Static Calls

[](#detecting-static-calls)

If you'd like to check if your method was called statically, call the `$this->staticallMethodCallWasStatic()` method.

```
use CodeDistortion\Staticall\Staticall;

class MyClass
{
    use Staticall;

    private function staticallMyMethod(): string
    {
        return $this->staticallMethodCallWasStatic() // myMethod(); // 'not called statically'
```

### Caveats When Using Staticall

[](#caveats-when-using-staticall)

#### Passing Parameters By Reference

[](#passing-parameters-by-reference)

Staticall uses PHP's `__call()` and `__callStatic()` magic methods to intercept method calls, and subsequently call the correct method.

Unfortunately PHP doesn't support the passing of parameters by reference in this way. This means that if you have a method that expects a parameter to be passed by reference, you won't be able to call it using Staticall.

The [PHP RFC: Allow explicit call-site pass-by-reference annotation](https://wiki.php.net/rfc/explicit_send_by_ref) was proposed in 2017 to try to address this, but it has become inactive.

#### Calling Nested Staticall Methods Statically

[](#calling-nested-staticall-methods-statically)

Calling a method statically using Staticall is not quite the same as calling a true static method. The way you call it is the same, but behind the scenes it's a little different. Staticall instantiates a new instance of the class and calls the method non-statically against that. This means that the method is not *actually* running in a static context. If you call another Staticall method from within your method statically, it will actually be called non-statically.

```
use CodeDistortion\Staticall\Staticall;

class MyClass
{
    use Staticall;

    private function staticallMyMethodA(): array
    {
        $calledStatically = $this->staticallMethodCallWasStatic()
            ? 'called statically'
            : 'called non-statically';

        return [
            'myMethodA' => $calledStatically,
            'myMethodB' => $this->myMethodB(), //  'called statically',
//   'myMethodB' => 'called non-statically' ]
```

To counteract this, you can proxy the call via another method in the same class that *is* actually static.

Testing This Package
--------------------

[](#testing-this-package)

- Clone this package: `git clone https://github.com/code-distortion/staticall.git .`
- Run `composer install` to install dependencies
- Run the tests: `composer test`

Changelog
---------

[](#changelog)

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

### SemVer

[](#semver)

This library uses [SemVer 2.0.0](https://semver.org/) versioning. This means that changes to `X` indicate a breaking change: `0.0.X`, `0.X.y`, `X.y.z`. When this library changes to version 1.0.0, 2.0.0 and so forth, it doesn't indicate that it's necessarily a notable release, it simply indicates that the changes were breaking.

Treeware
--------

[](#treeware)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/code-distortion/staticall) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

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

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

### Code of Conduct

[](#code-of-conduct)

Please see [CODE\_OF\_CONDUCT](.github/CODE_OF_CONDUCT.md) for details.

### Security

[](#security)

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

Credits
-------

[](#credits)

- [Tim Chandler](https://github.com/code-distortion)

License
-------

[](#license)

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

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance70

Regular maintenance activity

Popularity20

Limited adoption so far

Community9

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

Every ~149 days

Recently: every ~173 days

Total

8

Last Release

175d ago

PHP version history (4 changes)0.0.1PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\*

0.0.3PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\*

0.3.0PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\*

0.4.1PHP 7.0.\* | 7.1.\* | 7.2.\* | 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\* | 8.2.\* | 8.3.\* | 8.4.\* | 8.5.\*

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/56794290?v=4)[Tim](/maintainers/code-distortion)[@code-distortion](https://github.com/code-distortion)

---

Top Contributors

[![code-distortion](https://avatars.githubusercontent.com/u/56794290?v=4)](https://github.com/code-distortion "code-distortion (32 commits)")

---

Tags

static methods

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/code-distortion-staticall/health.svg)

```
[![Health](https://phpackages.com/badges/code-distortion-staticall/health.svg)](https://phpackages.com/packages/code-distortion-staticall)
```

###  Alternatives

[fisharebest/laravel-assets

Asset management for Laravel

208.1k](/packages/fisharebest-laravel-assets)

PHPackages © 2026

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