Noooo :( Notices are the enemy of all that is great and good.
If operator overloading is going to become a first-class feature then it
should be treated as such, and attempting overloading operators on
objects that don't have the relevant method available should trigger an
Error.
I agree with that throwing an error would be the better approach. But that
would be a breaking change, as it would break existing code. Something like
this is valid code in the moment:
$a = new ClassA();
$b = $a + 1;
Currently a only a notice (Object of class ClassA could not be converted to
int) is triggered, and the object is handled like a numeric 1. ($b have the
value 2).
I have no clue, how big the impact of changing this to an error would be, so
my current implementation just triggers an NOTICE.
In this RFC https://wiki.php.net/rfc/engine_warnings, it was decided to
remain the NOTICE behavior for casting an object to an int.
If it is decided to reclassify the usage of operators on objects (without
overloaded behavior) to thrown an Error, this would be totally fine for me,
but we should discuss this.
Greetings,
Jan Böhmer