Req #79669 [Com]: Nullable variables
| From: | valentiny510 at gmail dot com | Date: | Wed, 03 Jun 2020 12:05:56 +0000 |
| Subject: | Req #79669 [Com]: Nullable variables | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227294@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79669&edit=1
ID: 79669
Comment by: valentiny510 at gmail dot com
Reported by: valentiny510 at gmail dot com
Summary: Nullable variables
Status: Feedback
Type: Feature/Change Request
Package: Variables related
Operating System: nix
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
The example you gave $array['key'] ??= computeDefault(); is pointless,
To ASSIGN a default value for $a can be achived "normally"
$a = $b ?? compute_default( );
I want the ASSIGNMENT of $a to be NULLABLE if $b is NOT SET
$a = $b;
var_dump($a); null (without any errors!)
So I don't want the MANUALLY write
$array['key'] ??= NULL;
COMPRENDE?
Is the Exact behaviour I was talking about...
Damn, you guys confused me for a bit
Previous Comments:
------------------------------------------------------------------------
[2020-06-03 12:02:37] bugreports at gmail dot com
> $a ??= $b;
> where $b doesn't exists, still throw the error "Undefined variable: $b"
which is a good thing, i haven't seen "Undefined variable" in code which should not
be fixed the last 15 years and you should ask yourself why $b is undefined here
------------------------------------------------------------------------
[2020-06-03 11:51:13] valentiny510 at gmail dot com
oh sorry, is implemented, BUT... it DOESN'T do what I want,
I don't want to set a "default"
$a ??= $b;
where $b doesn't exists, still throw the error "Undefined variable: $b"
------------------------------------------------------------------------
[2020-06-03 11:50:03] bugreports at gmail dot com
> What version? I have seen the RFC, but I don't think is implemented yet
why don't you just do your homework and at least read the feature page of each new release or
at least try it out instead of thinking?
> and still ??= is 1 character larger than =?
that's ridiculous and null coalescing is always ?? so you don't have any point because
it's more important to be consistent within a programming language instead save one char
https://www.php.net/manual/de/migration74.new-features.php
Null coalescing assignment operator ¶
<?php
$array['key'] ??= computeDefault();
// is roughly equivalent to
if (!isset($array['key'])) {
$array['key'] = computeDefault();
}
?>
------------------------------------------------------------------------
[2020-06-03 11:42:52] valentiny510 at gmail dot com
btw, thank you
and still ??= is 1 character larger than =?
:P
it should be only ?= just like the others += *= etc...
------------------------------------------------------------------------
[2020-06-03 11:38:07] valentiny510 at gmail dot com
Not in 7.4.3
What version? I have seen the RFC, but I don't think is implemented yet
------------------------------------------------------------------------
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=79669
--
Edit this bug report at https://bugs.php.net/bug.php?id=79669&edit=1