-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Review the usage of apostrophes in error messages #5590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Review the usage of apostrophes in error messages #5590
Conversation
d79b570
to
e0f48c0
Compare
@@ -15,4 +15,4 @@ try { | |||
|
|||
?> | |||
--EXPECT-- | |||
Cannot access parent:: when current class scope has no parent | |||
Cannot access parent when current class scope has no parent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the usage of ::
is a bit weird, thus the removal. Can the new version still convey the message, right?
ext/ffi/ffi.c
Outdated
@@ -3462,11 +3462,11 @@ static int zend_ffi_validate_incomplete_type(zend_ffi_type *type, zend_bool allo | |||
ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(tags), key, tag) { | |||
if (ZEND_FFI_TYPE(tag->type) == type) { | |||
if (type->kind == ZEND_FFI_TYPE_ENUM) { | |||
zend_ffi_throw_parser_error("Incomplete 'enum %s' at line %d", ZSTR_VAL(key), FFI_G(line)); | |||
zend_ffi_throw_parser_error("Incomplete \"enum %s\" at line %d", ZSTR_VAL(key), FFI_G(line)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about these changes. Incomplete enum \"%s\"
, or Incomplete enum %s
should be the way to go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go for Incomplete enum \"%s\"
.
@@ -5328,7 +5328,7 @@ void zend_ffi_resolve_typedef(const char *name, size_t name_len, zend_ffi_dcl *d | |||
dcl->type = type; | |||
return; | |||
} | |||
zend_ffi_parser_error("undefined C type '%.*s' at line %d", name_len, name, FFI_G(line)); | |||
zend_ffi_parser_error("Undefined C type \"%.*s\" at line %d", name_len, name, FFI_G(line)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types shouldn't be quoted, so I guess I should remove them.
d7fe04e
to
77b5c19
Compare
Zend/zend_API.c
Outdated
@@ -2784,7 +2784,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_class_entry *sco | |||
*strict_class = 0; | |||
if (zend_string_equals_literal(lcname, "self")) { | |||
if (!scope) { | |||
if (error) *error = estrdup("cannot access self:: when no class scope is active"); | |||
if (error) *error = estrdup("cannot access self when no class scope is active"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In zend_ast.c
we use Cannot use "self" when no class scope is active
. Shouldn't these messages be consolidated into a common format? What should be the preferred format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer quoting "self"
here (same with "parent"
).
8f453ef
to
db16f6f
Compare
db16f6f
to
68f97be
Compare
6a348b0
to
841b18a
Compare
Zend/zend_API.c
Outdated
@@ -2784,7 +2784,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_class_entry *sco | |||
*strict_class = 0; | |||
if (zend_string_equals_literal(lcname, "self")) { | |||
if (!scope) { | |||
if (error) *error = estrdup("cannot access self:: when no class scope is active"); | |||
if (error) *error = estrdup("cannot access self when no class scope is active"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer quoting "self"
here (same with "parent"
).
Zend/zend_closures.c
Outdated
@@ -359,7 +359,7 @@ ZEND_METHOD(Closure, fromCallable) | |||
|
|||
static ZEND_COLD zend_function *zend_closure_get_constructor(zend_object *object) /* {{{ */ | |||
{ | |||
zend_throw_error(NULL, "Instantiation of 'Closure' is not allowed"); | |||
zend_throw_error(NULL, "Instantiation of Closure is not allowed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_throw_error(NULL, "Instantiation of Closure is not allowed"); | |
zend_throw_error(NULL, "Instantiation of class Closure is not allowed"); |
Zend/zend_constants.c
Outdated
@@ -456,7 +456,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope, | |||
|
|||
if (!c) { | |||
if (!(flags & ZEND_FETCH_CLASS_SILENT)) { | |||
zend_throw_error(NULL, "Undefined constant '%s'", name); | |||
zend_throw_error(NULL, "Undefined constant %s", name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think overall I'd prefer keeping quotes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what do you think about the Constant %s is deprecated
error? Should I use quotes here as well? Besides, we have the Undefined constant %s::%s
message where I'm unsure what to do.
I can come up with two possible logic:
- We only quote global constants, and class constants remain unquoted
- We treat the undefined constant error messages specially because they display non-existent (possibly bogus) constant names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My recent commit quotes many non-existent or unfound symbols (constants, functions, methods, properties). I think I like this format, because in most cases these symbol names can be empty, or contain bogus characters, if I got it right. How do like the new format?
However, the recently changed Undefined variable $%s
error message is an exception to the others, because I didn't quote it yet. Do you think it's a good idea to quote the variable name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the new version went a bit too far in the other direction. The main problem with the Undefined constant %s
error is that it becomes just "Undefined constant" if the name is empty, which has no indication that the name is actually empty (it would make sense as a standalone message).
I think the right rule of thumb here is to quote things that appear standalone, such as constant names, but not things that appear together with other symbols, such as undefined variables, methods etc. In particular, I don't think that Call to undefined method "Foo::()"
is any clearer than Call to undefined method Foo::()
.
I guess another possibility, that would work for most things apart from constant names, is to check whether the symbol name contains invalid characters, and in that case print Call to undefined method Foo::{""}()
and Undefined variable: ${"\xff"}
and similar. Not sure if worth it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestions, I wasn't able to come up with so sensible rule of thumbs :) I'll try to get rid of unnecessary quotes in my next commit.
Zend/zend_API.c
Outdated
@@ -331,13 +331,13 @@ ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pc | |||
*pce = zend_lookup_class(Z_STR_P(arg)); | |||
if (ce_base) { | |||
if ((!*pce || !instanceof_function(*pce, ce_base))) { | |||
zend_argument_type_error(num, "must be a class name derived from %s, '%s' given", ZSTR_VAL(ce_base->name), Z_STRVAL_P(arg)); | |||
zend_argument_type_error(num, "must be a class name derived from %s, \"%s\" given", ZSTR_VAL(ce_base->name), Z_STRVAL_P(arg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conjunction of quoted and unquoted class name here seems a bit odd. As we have a valid class here (which will use reasonable characters), I'd drop the quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense! :)
ext/ffi/ffi.c
Outdated
@@ -3462,11 +3462,11 @@ static int zend_ffi_validate_incomplete_type(zend_ffi_type *type, zend_bool allo | |||
ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(tags), key, tag) { | |||
if (ZEND_FFI_TYPE(tag->type) == type) { | |||
if (type->kind == ZEND_FFI_TYPE_ENUM) { | |||
zend_ffi_throw_parser_error("Incomplete 'enum %s' at line %d", ZSTR_VAL(key), FFI_G(line)); | |||
zend_ffi_throw_parser_error("Incomplete \"enum %s\" at line %d", ZSTR_VAL(key), FFI_G(line)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go for Incomplete enum \"%s\"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should include quotes for the constant error (and generally err on the side of quotes if there can be confusion).
33ec9c9
to
d03d2a7
Compare
@@ -1756,7 +1756,7 @@ ZEND_API int zend_startup_module_ex(zend_module_entry *module) /* {{{ */ | |||
if ((req_mod = zend_hash_find_ptr(&module_registry, lcname)) == NULL || !req_mod->module_started) { | |||
zend_string_efree(lcname); | |||
/* TODO: Check version relationship */ | |||
zend_error(E_CORE_WARNING, "Cannot load module '%s' because required module '%s' is not loaded", module->name, dep->name); | |||
zend_error(E_CORE_WARNING, "Cannot load module \"%s\" because required module \"%s\" is not loaded", module->name, dep->name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if module names should be quoted or not. The existing messages sometimes do it, sometimes not, totally inconsistently.
d03d2a7
to
1d19532
Compare
1b3b0a7
to
ea996c4
Compare
fad748b
to
55ac989
Compare
@@ -79,5 +79,5 @@ Cannot add element to the array as the next element is already occupied | |||
Illegal offset type | |||
Illegal offset type | |||
Cannot use a scalar value as an array | |||
Attempt to assign property 'foo' on bool | |||
Attempt to assign property 'foo' on bool | |||
Attempt to assign property "foo" on bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just realized that for bad array containers, we use on value of type %s
instead of on %s
. I'm not sure which format is preferred, but personally I find the former more accurate.
tests/classes/array_access_002.phpt
Outdated
@@ -134,11 +134,11 @@ ObjectOne::offsetGet(4th) | |||
int(4) | |||
ObjectOne::offsetGet(5th) | |||
|
|||
Notice: Undefined index: 5th in %sarray_access_002.php on line %d | |||
Notice: Undefined array index "5th" in %s on line %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the distinction between index and offset important? If not, we should probably settle on a single name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to keep the distinction between "5th"
and 5
(with/without quotes), but keeping the index/offset terminology is not. I would actually assume that both index and offset refer to an integer :) Maybe Undefined array key "5th"
, Undefined array key 5
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yess, array key
is the best choice, it didn't come to my mind before! :) I also agree with the rest, whether there are quotes or not is a very helpful thing!
4dc26dd
to
2328c85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From scrolling through this, I think it looks reasonable. We can adjust details later. There are some test failures that will have to be fixed first.
Zend/tests/bug39018.phpt
Outdated
@@ -64,39 +64,39 @@ print "\nDone\n"; | |||
--EXPECTF-- | |||
Warning: String offset cast occurred in %s on line %d | |||
|
|||
Warning: Uninitialized string offset: %s in %s on line %d | |||
Warning: Uninitialized string offset 430646668853805056 in %s on line %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably gonna fail on 32-bit.
@@ -7,7 +7,7 @@ $x = static::class; | |||
|
|||
?> | |||
--EXPECTF-- | |||
Fatal error: Uncaught Error: Cannot use "static" when no class scope is active in %s:3 | |||
Fatal error: Uncaught Error: Cannot use "static" in the global scope in %s:%d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/in the/from the
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you seem to also use from global scope
in some places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, after having a look at my changes again, I realized why I did it, and I think it was the right choice:
So in
is used together with use
, while from
is used together with call
. I think calling something from
sounds good, while using something from
is a bit unnatural. Another solution could be to write Cannot call "static" from the global scope
, but I think calling is mainly for functions, so it's probably still not perfect.
That said, are you ok with the current wording or do you still feel that a change is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong feelings here. From sounds more natural to me personally, but either is okay.
2328c85
to
bf868cc
Compare
bf868cc
to
e91745e
Compare
e91745e
to
9202feb
Compare
Feel free to ping me should you encounter any issues! I've already noticed some room for improvement in zend_compile.c, and I'll address these in my other PR - which should be my last bigger error message related PR for PHP 8.0. :) |
Additionally, I fixed some capitalization problems and improved some wordings.