Hey all,
I know this is a little late in the process, but it's something I've
noticed while prepping some content around 7.1.
This RFC: https://wiki.php.net/rfc/too_few_args
Passed, and has been implemented, but I feel that throwing an \Error
exception is a mistake. I think we should another more concrete exception
class for this error:
\TooFewArgumentsError extends \Error
A use case where this may trivially occur is where you are using argument
unpacking and the unpacked array is too small. Writing this, just looks bad:
try {
foo(… $args);
} catch (\Error $e) { }
compared:
try {
foo(… $args);
} catch (\TooFewArgumentsError $e) { }
Thoughts? Dmitry?
Given the tiny change this is, and that is backwards compatible with the
original RFC, I would like to add this to 7.1 for beta3.
I think I can make this change myself.
- Davey
Hey all,
I know this is a little late in the process, but it's something I've
noticed while prepping some content around 7.1.This RFC: https://wiki.php.net/rfc/too_few_args
Passed, and has been implemented, but I feel that throwing an
\Error
exception is a mistake. I think we should another more concrete exception
class for this error:
\TooFewArgumentsError extends \Error
A use case where this may trivially occur is where you are using argument
unpacking and the unpacked array is too small. Writing this, just looks
bad:try {
foo(… $args);
} catch (\Error $e) { }compared:
try {
foo(… $args);
} catch (\TooFewArgumentsError $e) { }Thoughts? Dmitry?
Given the tiny change this is, and that is backwards compatible with the
original RFC, I would like to add this to 7.1 for beta3.I think I can make this change myself.
- Davey
Problem: We already use TypeError for this for internal functions. If we
want to introduce an extra exception for this, lets use it for internal
functions as well. In that case we should probably go with something that
applies not just to too few arguments, but also to too many.
Nikita
Hey all,
I know this is a little late in the process, but it's something I've
noticed while prepping some content around 7.1.This RFC: https://wiki.php.net/rfc/too_few_args
Passed, and has been implemented, but I feel that throwing an
\Error
exception is a mistake. I think we should another more concrete exception
class for this error:
\TooFewArgumentsError extends \Error
A use case where this may trivially occur is where you are using argument
unpacking and the unpacked array is too small. Writing this, just looks
bad:try {
foo(… $args);
} catch (\Error $e) { }compared:
try {
foo(… $args);
} catch (\TooFewArgumentsError $e) { }Thoughts? Dmitry?
Given the tiny change this is, and that is backwards compatible with the
original RFC, I would like to add this to 7.1 for beta3.I think I can make this change myself.
- Davey
Problem: We already use TypeError for this for internal functions. If we
want to introduce an extra exception for this, lets use it for internal
functions as well. In that case we should probably go with something that
applies not just to too few arguments, but also to too many.
Are you saying that in PHP 7.0, if you call an internal function with too
few, or too many arguments it will emit a TypeError exception?
Can you provide examples? It's obviously not every function, e.g. fopen()
emits a Warning if you forget the second arg.
With that in mind, to make this BC, TooFewArguments would have to extend
TypeError which isn't great. Maybe, "ArgumentError" and the message will
make it clear if it's too few or too many?
- Davey
2016-08-06 11:53 GMT+02:00 Davey Shafik davey@php.net:
Hey all,
I know this is a little late in the process, but it's something I've
noticed while prepping some content around 7.1.This RFC: https://wiki.php.net/rfc/too_few_args
Passed, and has been implemented, but I feel that throwing an
\Error
exception is a mistake. I think we should another more concrete
exception
class for this error:
\TooFewArgumentsError extends \Error
A use case where this may trivially occur is where you are using
argument
unpacking and the unpacked array is too small. Writing this, just looks
bad:try {
foo(… $args);
} catch (\Error $e) { }compared:
try {
foo(… $args);
} catch (\TooFewArgumentsError $e) { }Thoughts? Dmitry?
Given the tiny change this is, and that is backwards compatible with the
original RFC, I would like to add this to 7.1 for beta3.I think I can make this change myself.
- Davey
Problem: We already use TypeError for this for internal functions. If we
want to introduce an extra exception for this, lets use it for internal
functions as well. In that case we should probably go with something that
applies not just to too few arguments, but also to too many.Are you saying that in PHP 7.0, if you call an internal function with too
few, or too many arguments it will emit a TypeError exception?Can you provide examples? It's obviously not every function, e.g.
fopen()
emits a Warning if you forget the second arg.With that in mind, to make this BC, TooFewArguments would have to extend
TypeError which isn't great. Maybe, "ArgumentError" and the message will
make it clear if it's too few or too many?
- Davey
I don't like "ArgumentError", how about "WrongArgumentCountError"? Maybe
also "WrongArgumentsError".
Regards, Niklas
Hey all,
I know this is a little late in the process, but it's something I've
noticed while prepping some content around 7.1.This RFC: https://wiki.php.net/rfc/too_few_args
Passed, and has been implemented, but I feel that throwing an
\Error
exception is a mistake. I think we should another more concrete exception
class for this error:
\TooFewArgumentsError extends \Error
A use case where this may trivially occur is where you are using argument
unpacking and the unpacked array is too small. Writing this, just looks
bad:try {
foo(… $args);
} catch (\Error $e) { }compared:
try {
foo(… $args);
} catch (\TooFewArgumentsError $e) { }Thoughts? Dmitry?
Given the tiny change this is, and that is backwards compatible with the
original RFC, I would like to add this to 7.1 for beta3.I think I can make this change myself.
- Davey
Problem: We already use TypeError for this for internal functions. If we
want to introduce an extra exception for this, lets use it for internal
functions as well. In that case we should probably go with something that
applies not just to too few arguments, but also to too many.Are you saying that in PHP 7.0, if you call an internal function with too
few, or too many arguments it will emit a TypeError exception?Can you provide examples? It's obviously not every function, e.g.
fopen()
emits a Warning if you forget the second arg.With that in mind, to make this BC, TooFewArguments would have to extend
TypeError which isn't great. Maybe, "ArgumentError" and the message will
make it clear if it's too few or too many?
Forgot to mention, this is only for strict_types=1, or if zpp explicitly
opts to throw (e.g. constructors).
Nikita