Req #53399 [PATCH]: Add E_STRICT when defining a required funcparameter after an optional parameter
| From: | carusogabriel@php.net | Date: | Mon, 13 Jan 2020 15:36:19 +0000 |
| Subject: | Req #53399 [PATCH]: Add E_STRICT when defining a required funcparameter after an optional parameter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224881@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53399&edit=1
ID: 53399
Patch added by: carusogabriel@php.net
Reported by: jbafford at zort dot net
Summary: Add E_STRICT when defining a required funcparameter
after an optional parameter
Status: Assigned
Type: Feature/Change Request
Package: Scripting Engine problem
PHP Version: *
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: Deprecate required param after optional
On GitHub: https://github.com/php/php-src/pull/5067
Patch: https://github.com/php/php-src/pull/5067.patch
Previous Comments:
------------------------------------------------------------------------
[2017-03-27 20:53:42] tpunt@php.net
Related to bug #68445
------------------------------------------------------------------------
[2011-10-16 00:20:02] stas@php.net
I think the idea is good, however the patch seems too complicated. I do not think
we need additional flag and not sure why would we need additional pass through
arguments to do it - if we say everything after certain arg is optional, then we
already know how to do it, we have settings for that in args structure. And we can
detect this stuation immediately when we parse the arguments on compile.
------------------------------------------------------------------------
[2010-11-24 16:25:43] jbafford at zort dot net
Description:
------------
PHP does not emit a warning of any kind when defining a function with a required
parameter after an optional parameter. For example:
function foo($optional = 1, $required) {}
It doesn't make sense to define a required parameter after an optional one,
since
that effectively makes all preceding optional parameters required. Since this is
an error that can produce bugs and other warnings if one is not careful (calling
the above function with less than two parameters will cause warnings to be
emitted
for the missing $required parameter), PHP should emit a warning of some kind
when
functions like this are defined.
The attached patch includes the following changes:
* add an E_STRICT warning when such a function is defined. (The warning will
only
appear when E_STRICT is included in the php.ini, since it happens at script
compile time, before error_reporting can be called.)
* add Zend/tests/func_optarg1.phpt and Zend/tests/func_optarg2.phpt to test for
the presence and absence of the warning
* Fixes Zend/tests/call_user_func_005.phpt, which fails with the warning added.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53399&edit=1