Req #79669 [Com]: Nullable variables

From: Date: Wed, 03 Jun 2020 19:36:54 +0000
Subject: Req #79669 [Com]: Nullable variables
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227306@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: Suspended Type: Feature/Change Request Package: Variables related Operating System: nix PHP Version: Next Major Version Block user comment: N Private report: N New Comment: You can see the @ operator as a general purpose "error messages supresser". A "null assigner" or whatever you want to call it, have a different implementation and can be a bit faster, (negligeable but still...) Previous Comments: ------------------------------------------------------------------------ [2020-06-03 19:21:09] valentiny510 at gmail dot com I just checked and realized that the SDTERR handler doesn't have if (!($code & error_reporting( ))) return; # Error silenced "@" Sorry, mea culpa... for the $a = @$b; example (third party software...) but still feels like I'm cheating somehow, because you know that the error happend, the parser triggered the error, but you just choose to silence it like you can silence many other errors, is not exactly the same as coalescing and I maintain the position with other symbols/operators ------------------------------------------------------------------------ [2020-06-03 18:51:15] requinix@php.net > You don't get it either... Let me spell this out for you: 1 <?php 2 3 $a = $b; 4 $c = @$d; Line 3 produces a warning. Of course it does. Line 4 DOES NOT. ------------------------------------------------------------------------ [2020-06-03 18:48:48] valentiny510 at gmail dot com Just think what the coalence operator do (in +/- english...) $a = $b ?? null; 1. create $a = 2. Evaluate the "expression $b" to null 3. go to the next "expression" 4. Evaluate the "expression null" to null 5. ask if there are more expressions and if there are not return the null from step 4 The step 2 was ALREADY EVALUATED to null, and I can I ASK the parser, "If you find this operator, (placeholder)... give me whatever you Evaluated on the step 2 no matter what it is, its value or null otherwise" so it will skip all the next steps 3, 4, 5, etc... and as you can see, there are Two expressions that evaluates to null, and is why I said I think that is a bit redundant, and maybe... just maybe, returning whatever it is in the step 2 can improve the speed in some cases. ------------------------------------------------------------------------ [2020-06-03 18:28:42] valentiny510 at gmail dot com You don't get it either... Your example "https://3v4l.org/03cuu" produce the same error for Either... $a = @$b; or @$a = $b; "Notice: Undefined variable: b in /in/03cuu on line 3" I want to get rid of the error message and have a short operator that assign the null to the variable $a automatically but ONLY IF $b doesn't exists... like "self casting to null" or similar... $a = (null?) $b; I really don't know what to say to make myself understandable more than I already did... Thank you for your time guys ------------------------------------------------------------------------ [2020-06-03 17:55:23] requinix@php.net > $a = @$b; (btw this doesn't work either...) Yes it does. https://3v4l.org/03cuu For more complicated expressions you can promote the @ to the whole assignment: > @$a = $b + $c; ------------------------------------------------------------------------ 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

« previous php.bugs (#227306) next »