Req #70278 [Opn]: Allow null to be passed by reference

From: Date: Tue, 12 Mar 2019 15:37:49 +0000
Subject: Req #70278 [Opn]: Allow null to be passed by reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219928@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70278&edit=1 ID: 70278 User updated by: cyslider at posteo dot de Reported by: cyslider at posteo dot de Summary: Allow null to be passed by reference Status: Open Type: Feature/Change Request Package: *General Issues PHP Version: Next Major Version Block user comment: N Private report: N New Comment: That is what my IDE shows me. Also a bug? function exec ($command, array &$output = null, &$return_var = null) {} I understand 'array &$output = null' as having null by default. Sorry if this is not meant that way internally. I am not aware of that. I thought this notation always refers to setting a default value in case the value is omitted. Previous Comments: ------------------------------------------------------------------------ [2019-03-12 14:49:03] cmb@php.net The default value of the $output parameter of exec() is not NULL; actually, this parameter has no default value. Either the argument is omitted, or not. Anyhow, this feature request is obviously controversial, so it should be discussed on <internals@lists.php.net>, and might need the RFC process[1]. [1] <https://wiki.php.net/rfc/howto> ------------------------------------------------------------------------ [2019-03-12 13:48:39] cyslider at posteo dot de All I am saying is that having to pass null by reference to a function that explicitly states to accept null as a value, even as its default, is odd. ------------------------------------------------------------------------ [2019-03-12 09:37:01] spam2 at rhsoft dot net yes it is because the default value means "don't store it anywhere" and honestly what sort of argumentation is "i always need to remember it"? for your IDE:make a bugreport there that they should stop warn about correct usage and start warning about your repeated mistake you never remember ------------------------------------------------------------------------ [2019-03-12 09:04:44] cyslider at posteo dot de > there is no reason for the first line to begin with at all Tell this my IDE that warns me of an undefined variable which is, at least in eclipse, not suppressible. But far more annoying is that I have to remember this as I always initially pass null and get that error, then have to go back and correct it. The extra line is less of an issue to me. Is it really that hard, to allow null at the point where this error is generated, at least if the default value allows null? Is there a reason not to always allow null, even? >> Beside that, often this functions are declared in includes so >> I have no control over how the function is defined. >This is certainly true, but that doesn't automatically mean that the language >should be changed, rather than just the third-party code you are calling into. >File a bug with them if you think their function signatures could be more >useful - you'll probably get a faster turnaround than waiting for a new stable >version of PHP anyway! exec is part of PHP core. So consider this advice of rowan collins followed :-) ------------------------------------------------------------------------ [2019-03-11 18:19:15] spam2 at rhsoft dot net > $null = null > exec($script, $null, $result) there is no reason for the first line to begin with at all [harry@srv-rhsoft:/downloads]$ php test.php [harry@srv-rhsoft:/downloads]$ cat test.php <?php declare(strict_types=1); exec('hostname', $null, $result); ?> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=70278 -- Edit this bug report at https://bugs.php.net/bug.php?id=70278&edit=1

« previous php.bugs (#219928) next »