Well, in this case this signature is obliging the value passed to implement the interface Textelementinterface. The example below is very simple, but I believe it is suitable for the question:
<?php
interface TextElementInterface
{
public function __construct($pText);
}
class ImplementaInterface implements TextElementInterface
{
public function __construct($pText) {
return $pText;
}
}
class MinhaClasse
{
public function chamarMetodo(TextElementInterface $pText = null) {
echo "Opa! Funciona.";
}
}
$obj = new MinhaClasse;
$obj->chamarMetodo(new ImplementaInterface('Qualquer coisa aqui'));
Note that I passed as parameter new ImplementaInterface('Qualquer coisa aqui')
, this class is implemented the ** Textelementinterface interface**.
If you try something like: $obj->chamarMetodo('Qualquer coisa aqui');
you will see that error occurs because the interface is not being implemented.
you have no class that implements this interface?
– rray
@rray has this comment in the //Rich text element interface library. and It has a rich text class, but I do not see in it the implementation of this interface.
– Julio Henrique
If she implemented, just call the normal methods?
– Julio Henrique
The idea is exactly the same, the only detail is that the class you need to instantiate needs to be an implementation of this interface. Which class would that be depends on the context, what you’re doing and which library it is.
– Woss
If you implement, just pass this object as an argument and you can call the methods normally. Note that the interface forces you to implement some methods. Setting the parameter type as an interface allows you to make 'input' more flexible'.
– rray
@Andersoncarloswoss library is PHPOFFICE - Phppresentation
– Julio Henrique