1

I have a MultipleException class that collects exceptions (e.g. multiple errors in form fields) and implements countable, but I don't want it to be iterable like a list, cause it is actually an exception (you would never throw a list).

Is this okay in terms of software design? Or am I misusing the SPL Countable interface?

Which is the right way?

Thanks

itsjavi
  • 2,574
  • 2
  • 21
  • 24

1 Answers1

4

It is okay.

Countable is there so that any of your classes can customise the value returned from calling count() with an instance. It is completely separate from a class being iterable.

salathe
  • 51,324
  • 12
  • 104
  • 132