Download the PHP package gwangjinkim/php-multidispatch without Composer

On this page you can find all versions of the php package gwangjinkim/php-multidispatch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-multidispatch

php-multidispatch: Multiple Dispatch (with CLOS Extensions) for PHP

Packagist Tests

A modern, readable, CLOS-inspired multiple dispatch library for PHP—now with support for :primary, :before, :after, :around, and call-next-method! Open-Closed Principle in action, no fuss.


What is Multiple Dispatch? (And Why Should You Care?)

Multiple dispatch lets you write functions whose behavior depends on the runtime types of all their arguments—not just the first one (like in classic OOP). Imagine polymorphism that’s not boxed into inheritance hierarchies, with the freedom to extend methods for new types, even across package boundaries.

Why is this awesome?

Multiple Dispatch allows you to import a package (which uses Multiple Dispatch) and extend it without ever having to touch or change its internal code (tests, definitions), but just add more classes and more methods/functions. It allows you to follow open-closed principle which would be impossible with classical Java/C++ OOP systems.


Features


Table of Contents

  1. Installation
  2. Classic Usage (No CLOS Extensions)
  3. CLOS Extensions: :primary, :before, :after, :around, and call-next-method
  4. Extended Example: CLOS in PHP
  5. Testing
  6. Troubleshooting
  7. Links & References

Installation

With Composer

Use :dev-main to get the newest version! Specify version numbers when you want to downgrade or pin a version.

Or add to your composer.json:

Eventually use "^0.3.1" e.g., to pin to a version.

Requirements

PHP Installation Shortcuts


Dispatch Policy: first-wins vs last-wins

You control which matching handler "wins" when there are multiple equally-specific possibilities (for example, two interfaces, or multiple wildcards).

Default: last-wins for maximum extensibility, but you can switch any dispatcher at any time:

Use DispatchPolicy::FirstWins for backwards compatibility or stricter method resolution.

Policy Which handler wins? When to use
first-wins First registered Strict/classic OOP, legacy, backward-compat
last-wins Last registered (default) Override style, plugin/extensible systems

Classic Usage: Multiple Dispatch the Simple Way (No CLOS Extensions)

If you just want plain, classic multiple dispatch—no :before, :after, or :around—your code stays as simple and clean as before. Everything you knew still works, and it’s all backwards-compatible!

Here’s how you use the package the “old-school” way (like before CLOS extensions):

How it works:

When to use:

Note: You can always choose whether registration order is first-wins or last-wins, per-dispatcher, using setDispatchPolicy. The default is last-wins, but all older code is fully supported.


Why CLOS? (And What Makes It Different?)

Why all this talk about CLOS (the Common Lisp Object System)?
CLOS is the most advanced, flexible object system ever built—letting you combine, stack, override, and wrap behavior with surgical precision.
With these extensions, you can:

It’s a friendlier, more composable way to program.
And it’s 100% optional—you can stick with classic style if you like!

CLOS-Style Method Combination

Inspired by the Common Lisp Object System (CLOS), you can now combine multiple method types:

Registration Syntax:

Example:

Output:

How the Method Combination Works:

  1. All matching :before methods are called, from most specific to least.
  2. All :around methods wrap the chain (most specific is outermost).
  3. The most specific :primary method is called.
  4. All matching :after methods are called, from least specific to most.

You can combine :before, :after, :primary, and :around on any type signature.


Extended CLOS Example

Here is a full, extended example to clarify usage and show best practices—great for both CLOS and non-CLOS users.

What you'll see:

How to Think About Each Method Type:


Detailed CLOS Example With Explanations

Output:

What’s happening?


Pro tip: Want several :around? Just register more! They stack “outside-in” (the last registered is the innermost).


Testing

Run your tests with PHPUnit:

You’ll see all your dispatch rules and method combinations in action. Both classic and CLOS-style tests are included.


Troubleshooting

If you get stuck, check out the examples or open an issue.


Links & References


Contributors / Authors


Call to Action

Ready to write cleaner, more extensible PHP—no more “if-else soup”?
Try it out!

Whether you want classic dispatch, CLOS power features, or both, you’re covered.
Enjoy dispatching!


All versions of php-multidispatch with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gwangjinkim/php-multidispatch contains the following files

Loading the files please wait ...