#StackBounty: #java #php #runnable #porting #command-pattern How to migrate a java command pattern using runnable to PHP 7.4?

Bounty: 150

For studying purpose, I am trying to migrate this Java Command Pattern example to PHP:


As @simon commented, using method reference operator, would modernize quite a bit the code:

class MyCommand implements Order {
    private final Runnable action;

    public MyCommand(Runnable action) {
         this.action = action;

    public void execute() {

And then you could create commands like this:

MyCommand bsc = new MyCommand(stock::buy);
MyCommand ssc = new MyCommand(stock::sell);

My current PHP implementation is here: https://3v4l.org/iIHn9

So what is the best approach to implement the MyCommand Class in PHP?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.