Req #47783 [Opn->Csd]: Error messages often don't make sense.

From: Date: Mon, 22 Jun 2015 08:19:06 +0000
Subject: Req #47783 [Opn->Csd]: Error messages often don't make sense.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193746@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=47783&edit=1 ID: 47783 Updated by: kalle@php.net Reported by: nairbv at yahoo dot com Summary: Error messages often don't make sense. -Status: Open +Status: Closed Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues PHP Version: 5.2.9 -Assigned To: +Assigned To: kalle Block user comment: N Private report: N New Comment: Let me clarify these a little for you: #42118 - There was no type hinting at the time, in fact it is just being introduced now with PHP 7. #41948 - E_RECOVERABLE_ERROR is an error, not an exception, but it could have been caught with a catch block if ErrorException + set_error_handler() was used. #44565 - The example not working was because &$obj->method() means $obj->method() returns a string, that is then written to a temp string with, but you cannot reference a temp string so that is why you cannot write to that context. If the method return value was intended to have a return value that was going to be a refence, then the method signature should be declared as such and the usage context have been different. As for the issue you stated: "Catchable fatal error: Argument 1 passed to my_function() must be an instance of string, string given" does not make sense. While I understand that it may not be crystal clear for all, then keep in mind that PHP supports objects and primitive types, objects are "instances" and primitives are well, just primitives. But there is good news for you, as of PHP7 we have scalar type declarations (and even return type hinting). We are always open for PR's on Github if you feel like you can improve the error message. Previous Comments: ------------------------------------------------------------------------ [2009-03-26 03:23:55] nairbv at yahoo dot com Description: ------------ Error messages often don't make sense. for example: Catchable fatal error: Argument 1 passed to my_function() must be an instance of string, string given I'd comment on this bug: http://bugs.php.net/bug.php?id=42118 But this reporting system doesn't permit commenting on existing bugs. The bug is NOT bogus. The error message IS non-sense. It's fine if you're not going to support primitive type hinting, but the message should say something to that effect. Also the error is NOT "catchable." See bug: http://bugs.php.net/bug.php?id=41948 Again, I'd comment on that bug, but I can't comment on existing bugs. If the error can only be handled by setting an error handler, and not caught with a "catch" block, the error message should say "RECOVERABLE error" or "handleable" or something to that effect, not "catchable error." Other bad error messages include: "Can't use method return value in write context" see bug: http://bugs.php.net/bug.php?id=44565 "write context" is meaningless to the programmer. On that bug, the reporter commented that the message is not helpful. Why was the bug closed instead of fixing the error message?? Reproduce code: --------------- for the first error message: function my_function(string $str) {} bar(''); for the second error message: empty($foo->getValue()); or also the code in bug #44565. Expected result: ---------------- error messages that help the programmer. for the "catchable" error regarding type hinting: Either something like: "Recoverable fatal error: reference to undefined class 'string' on line [line of type hint]" or: "Recoverable fatal error: Argument 1 passed to my_function() must be an instance of class string, primitive string given." For the empty($foo->getbar());"write context" message: It should probably say something like "cannot use method return value when calling internal language constructs" ... or something like that. For the "write context" message referenced in bug 44565: it should give the '"call-time pass-by-reference" is deprecated when you use & in foo(&$a);' like the documentation (http://docs.php.net/manual/en/language.references.pass.php) says it will. Actual result: -------------- Useless (and sometimes amusing) error messages like "must be an instance of string, string given" or the "write context" message which as far as I know is in reference to some implementation detail internal to php. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=47783&edit=1

« previous php.bugs (#193746) next »