Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
Is it ok to use constants in many of my written classes? Since constants are global, including a file with a bunch of define()'s in the main script makes them available to all objects used in that script. Those aren't any special data or anything, just language strings (translated user-end messages/errors etc). It's very convenient for me this way, I can simply use eg
in some class and be fine with it. But is it an ok way to do it? What if the file get's larger? Say, a few hundred define()'s? Could there be any performance issues?
I'd tend to see error messages as belonging to the class which identified the error state, or perhaps to a client which received a false value when it requested something from another object - hence they'd be class properties.
For multi-language errors, you could maybe return an id and then look up a phrasebook - a simple container defining a bunch of strings.
It's often useful to customise an error using sprintf to add some details, eg: