Answer the question
In order to leave comments, you need to log in
How to pass an interface as a parameter?
There is a class and an interface
<?php
class Test
{
public function __construct(SomeInterface $someInterface){
$this->someInterface = $someInterface;
}
}
interface SomeInterface
{
public function foo($tmp){}
}
Answer the question
In order to leave comments, you need to log in
class Test
{
public function __construct(SomeInterface $someInterface)
{
$this->someInterface = $someInterface;
}
}
interface SomeInterface
{
public function foo($bar);
}
class SomeClass implements SomeInterface
{
public function foo($bar)
{
}
}
$a = new SomeClass("bar");
$b = new Test($a);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question