Req #80354 [NEW]: allow casting to void (no-op)
| From: | divinity76 at gmail dot com | Date: | Thu, 12 Nov 2020 15:20:47 +0000 |
| Subject: | Req #80354 [NEW]: allow casting to void (no-op) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-230301@lists.php.net to get a copy of this message | ||
From: divinity76 at gmail dot com
Operating system:
PHP version: Next Minor Version
Package: Scripting Engine problem
Bug Type: Feature/Change Request
Bug description:allow casting to void (no-op)
Description:
------------
i wish casting to void was legal, doing the same thing as casting to
void in C: a no-op. (used to shut up linters about unused variables)
there are some situations where you have to accept arguments that you
don't use, or have to pass a variable by reference that you don't
actually care about, and some linters may warn you about "this variable
is declared but never used" or "this variable is written to but never
read", for example CURLOPT_HEADERFUNCTION: the first argument is the
curl handle and the 2nd argument is the header, some code only cares
about the header, but have to accept the curl argument too just to match
the CURLOPT_HEADERFUNCTION callback signature (in my experience, the
handle argument is only useful when using the curl_multi api, and not
useful when using the non-multi api)
Test script:
---------------
<?php
$recieved_headers = [];
$curlopts = array(
CURLOPT_HEADERFUNCTION => function ($ch, string $header) use
(&$recieved_headers): int {
(void) $ch;
$recieved_headers[] = $header;
return strlen($header);
}
);
function f(&$val1, &$val2, &$val3)
{
// lets pretend this function writes to val1/val2/val3
}
$data_i_need = null;
$data_i_dont_need = null;
f($data_i_need, $data_i_dont_need, $data_i_dont_need);
(void)$data_i_dont_need;
Expected result:
----------------
(blank)
Actual result:
--------------
Parse error: syntax error, unexpected '$ch' (T_VARIABLE) in /in/uWlu5 on
line 5
Process exited with code 255.
--
Edit bug report at https://bugs.php.net/bug.php?id=80354&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80354&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80354&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80354&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80354&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80354&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80354&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80354&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80354&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80354&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80354&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80354&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80354&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80354&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80354&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80354&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80354&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80354&r=mysqlcfg