Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anonymous interface implementation in php

In Java we can do like this..

interface Inter {
    public void run()
}

class Test {
    public Test(Inter inter){
        inter.run();
    }
}

new Test(new Inter() {
    @Override
    public void run() {
        //Some Task;
    }
}

But in php I got error while doing like this. Isn't it possible to do this in php?

like image 928
Samundra Khatri Avatar asked Oct 15 '25 14:10

Samundra Khatri


1 Answers

A little late, but you can do this in php:

new Test(new class implements Inter {
    public function run()
    {
        // Some Task;
    }
});
like image 78
DASPRiD Avatar answered Oct 18 '25 05:10

DASPRiD