You ask if this is possible: yes, but ...
If you are implementing an interface, you must abide by its contract .
interface Loggable { public function log(); }
You can call log() with this interface contract without any parameters .
To do this, you can make the parameter optional:
class QMSLogger implements Loggable { public function log($queueName = null) { ... } }
This is a well-functioning PHP , and it follows the Liskov Substitution Principle. Of course, you should not use this optional parameter when coding with an interface , otherwise you are obviously breaking the interface. Such a parameter can be useful only when you use an implementation (for example, in some part of the code that is closely related to QMSLogger ).
However, this is probably not the solution to your problem, since $queueName seems to be a configuration value, and it might be better to pass it in the class constructor (as explained in another answer).
Matthieu napoli
source share