PHPackages                             trismegiste/php-is-magic - 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. trismegiste/php-is-magic

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

trismegiste/php-is-magic
========================

Library of useful magic tricks for PHP

29134[2 issues](https://github.com/Trismegiste/Php-Is-Magic/issues)PHP

Since Sep 27Pushed 12y ago2 watchersCompare

[ Source](https://github.com/Trismegiste/Php-Is-Magic)[ Packagist](https://packagist.org/packages/trismegiste/php-is-magic)[ RSS](/packages/trismegiste-php-is-magic/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP is Magic
============

[](#php-is-magic)

[![Pony](./doc/img/pony.jpg)](./doc/img/pony.jpg)

Ok, you already know that PHP is slow, memory intensive and with inconsistent syntax.

So, where are the plus sides ?

This interpreted language has some hidden magic. This library tries to use it without messing your project.

Despite the funny pics, this lib is fully tested : [![Build Status](https://camo.githubusercontent.com/877f12d6564f8c1c2eed8cdb86068e3ad8aa598fa9d782a0b7b3b408ae54a0ba/68747470733a2f2f7472617669732d63692e6f72672f547269736d6567697374652f5068702d49732d4d616769632e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Trismegiste/Php-Is-Magic)

Eval
----

[](#eval)

"eval is evil" (sounds good, I like that). O RLY ? Eval is very powerful. But with great power comes great responsibility. Most of the mockup frameworks ([PHPUnit](https://github.com/sebastianbergmann/phpunit-mock-objects/blob/master/PHPUnit/Framework/MockObject/Generator.php#L272) for example) use eval. So, is this the Evil serving for the Good ? Seems so.

Magic method \_\_call
---------------------

[](#magic-method-__call)

This magic method is powerful but it does not replace "strong" type-hinting. Practical for fast prototyping, it is not suited for further maintenance. Use it with cautions.

[![color](./doc/img/gandalf.jpg)](./doc/img/gandalf.jpg)

Reflection
----------

[](#reflection)

Long time ago, in a far far away galaxy I was coding with VC++ and RTTI was not in the standard. Later, Java has reflection but very slow compared to its average speed. Now PHP has reflection and not much slower than its average "slowness". Using it is not an issue.

Trait
-----

[](#trait)

Traits are very efficient. At first I was very skeptical but now, with good conventions, I think it is THE real shit of PHP. They have the power of multi-inheritance and solving the [diamond problem](http://en.wikipedia.org/wiki/Multiple_inheritance#The_diamond_problem).

[![shrike](./doc/img/nagato.jpg)](./doc/img/nagato.jpg)

Closure
-------

[](#closure)

I'm talking about bound closures i.e linked to an object, not [lamba functions](http://en.wikipedia.org/wiki/Anonymous_function). Many design patterns (like Strategy and Command) can benefit from closures.

Parsing PHP with PHP
--------------------

[](#parsing-php-with-php)

There is a wonderful libray called nikic/PHPParser which does magic too. Redefining and changing dynamically a class is possible but very slow.

[![harry](./doc/img/harry.jpg)](./doc/img/harry.jpg)

So what ?
---------

[](#so-what-)

By combining all these features, I'll try to gather some magic tricks which can be useful, specially when dealing with legacy code. I like to think most of the tools provided here are like **simulators** and not always good practices (specially true for design pattern simulators)

Simulators can be helpful in early stage of development when your design are not finished and you want to test which pattern is suited to solve your problem. Well, at least it's better than copy-paste some scripts from an old project :)

Read the listing of features in this library :

- [Design Pattern simulator/implementor](/src/Trismegiste/Magic/Pattern)
- [Fast Prototyping (boilerplate)](/src/Trismegiste/Magic/Proto)

Notes
-----

[](#notes)

Despite the fact that magic is a potential WTF generator, I try to minimize problems by forcing the use of interface, adding many validators and also preventing mis-uses of some tools (see DecoratorBuilder for example).

It is also an another way to explore common patterns with new features. For example, I believe traits will change the future of PHP frameworks (in fact it has [already started](http://silex.sensiolabs.org/doc/usage.html#traits)).

Doc
---

[](#doc)

I have written a readme for each tool in its folder

TODO
----

[](#todo)

- bundle for symfony

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/64cc99ca21a090b2454784670e4ac49db17794d6861078eeceebdbe302365c3f?d=identicon)[trismegiste](/maintainers/trismegiste)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/trismegiste-php-is-magic/health.svg)

```
[![Health](https://phpackages.com/badges/trismegiste-php-is-magic/health.svg)](https://phpackages.com/packages/trismegiste-php-is-magic)
```

###  Alternatives

[fullcalendar/fullcalendar

Full-sized drag &amp; drop event calendar

20.4k373.3k4](/packages/fullcalendar-fullcalendar)

PHPackages © 2026

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