91 reputation
8
bio website github.com/chriso
location Sydney, Australia
age 26
visits member for 3 years, 3 months
seen Oct 5 '12 at 7:22

I'm a software developer living in Sydney, Australia.


May
6
awarded  Nice Question
Oct
15
awarded  Popular Question
Apr
7
awarded  Self-Learner
Apr
4
awarded  Promoter
Apr
1
awarded  Teacher
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
@Matthew agreed. Thanks for your thoughts :)
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
@Matthew true, but IMO triggering an error on an invalid method call isn't poor design 1) many (most?) languages have it built-in, and 2) I can't think of a single case where you would ever want to catch an invalid method call and handle it?
Apr
1
revised `trigger_error` vs `throw Exception` in the context of PHP's magic methods
deleted 813 characters in body
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
@Matthew for consistency. I'm not debating exceptions vs. errors (there is no debate) or whether PHP has design fails (it does), I'm arguing that in this very unique circumstance, for consistency, it's best to mimic the behaviour of the language
Apr
1
revised `trigger_error` vs `throw Exception` in the context of PHP's magic methods
edited title
Apr
1
revised `trigger_error` vs `throw Exception` in the context of PHP's magic methods
added 100 characters in body
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
@Matthew Node.JS / JavaScript triggers an error that can't be caught
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
@Matthew thanks - TIL errors in Ruby and Python are exceptions.
Apr
1
answered `trigger_error` vs `throw Exception` in the context of PHP's magic methods
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
If you read my second edit you'll see my use-case. Say you have two implementations of the same class, one using __call and one with hardcoded methods. Ignoring the implementation details, why should both classes behave differently when they implement the same interface? PHP will trigger an error if you call an invalid method with the class that has hardcoded methods. Using trigger_error in the context of __call or __callStatic mimics the default behaviour of the language
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
"calling a method that doesn't exist may be a valid possibility" - I completely disagree. In every language (that I've ever used), calling a function/method that doesn't exist will result in an error. It is not a condition that should be caught and handled. Static languages won't let you compile with an invalid method call and dynamic languages will fail once they reach the call.
Apr
1
comment `trigger_error` vs `throw Exception` in the context of PHP's magic methods
Thanks for the response :) - 1) I agree that exceptions should almost always be used over errors - all of your arguments are valid points. However.. I think that in this context your argument fails..
Apr
1
revised `trigger_error` vs `throw Exception` in the context of PHP's magic methods
added 84 characters in body
Apr
1
awarded  Student
Apr
1
awarded  Editor