oop - PHP Working with Interfaces some advice needed


I have just discovered the joys of interfaces. I always knew they existed but being able to check if the class is an instanceof an interface has allowed me to add a nice amount of flexibility and the around the various objects that i'm using.

i realise that i can have any number of interfaces and i've read that it might be best to not have too many. so i'm curious as to how much i should interface.

forexample i want to add things like Interface_Images that has functions and calls for hasImages, getImages etc... that way in my views i can simply do

if(object instanceof Interface_Images) { 
  // do something 
} else {
  if(object->hasImages()) {
    // do something else

is it worth me doing this?




Follow Interface segregation principle and use so many as you need.

Also use is_callable for checking methods if you cannot use iterfaces.

People are also looking for solutions to the problem: PHP to execute PHP on another server and get the result


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.