Jump to content

Exception suitable for "Read-Only"


phant0m

Recommended Posts

Hi

 

I am implementing a read-only access to some specific attributes of a class via the magic __get method. I intend to raise an exception when trying to write to it using __set, but I'm not sure which exception is suitable to use.

 

Is there any predefined exception to indicate such an error or should I just go ahead and define my own?

Link to comment
https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/
Share on other sites

I have been thinking about using "LogicError", because in a way, it is I think, since you are not supposed to assign to it.

 

The other I was thinking about was something along the lines of Myframework_Types_Property_ReadOnlyException but I don't like that level of verbosity too much, to be honest :)

Any other thougts on this?

 

Not really besides, "don't think too much about it." :P  The LogicException is fine (and would be the one that I would choose), unless you have any particular need or convention to have one specific to your framework.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.