phant0m Posted December 7, 2010 Share Posted December 7, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/ Share on other sites More sharing options...
salathe Posted December 7, 2010 Share Posted December 7, 2010 Which exception(s), if any, have you been considering? If you did make your own, what would it be? Quote Link to comment https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/#findComment-1143897 Share on other sites More sharing options...
phant0m Posted December 7, 2010 Author Share Posted December 7, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/#findComment-1143900 Share on other sites More sharing options...
salathe Posted December 7, 2010 Share Posted December 7, 2010 A LogicException would be fine, as it (trying to write to a read-only property) would be a logic error. Quote Link to comment https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/#findComment-1143955 Share on other sites More sharing options...
phant0m Posted December 7, 2010 Author Share Posted December 7, 2010 Ah yes, LogicException it is, not Error Any other thougts on this? Quote Link to comment https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/#findComment-1143967 Share on other sites More sharing options...
salathe Posted December 7, 2010 Share Posted December 7, 2010 Any other thougts on this? Not really besides, "don't think too much about it." 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. Quote Link to comment https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/#findComment-1143970 Share on other sites More sharing options...
phant0m Posted December 7, 2010 Author Share Posted December 7, 2010 Hehe, yeah that may be a problem of mine.. spending too much time thinking instead of just giving things a shot Thanks of lot for the input. Quote Link to comment https://forums.phpfreaks.com/topic/220902-exception-suitable-for-read-only/#findComment-1143972 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.