Skip to main content
51 events
when toggle format what by license comment
Nov 2 at 7:07 history edited Your Common Sense CC BY-SA 4.0
added 1071 characters in body
Aug 23, 2024 at 14:55 comment added Dan Gravell Maybe worth adding that when declaring an anonymous function you'll get undefined variable if you don't declare the variable in the use clause.
Mar 24, 2023 at 5:43 history edited Your Common Sense CC BY-SA 4.0
added 592 characters in body
Mar 20, 2023 at 7:16 history edited Your Common Sense CC BY-SA 4.0
added 318 characters in body
Mar 20, 2023 at 5:03 history edited Your Common Sense CC BY-SA 4.0
added 639 characters in body
Mar 5, 2023 at 6:56 history edited Your Common Sense CC BY-SA 4.0
this answer initially dwelled on how to circumvent the error, I tried to make it actually helpful.
Mar 3, 2023 at 11:56 history edited Your Common Sense CC BY-SA 4.0
more clarification
Jan 24, 2023 at 11:44 history edited CarlosCarucce CC BY-SA 4.0
fix word 'avoid'
Jan 5, 2023 at 12:43 history edited Your Common Sense CC BY-SA 4.0
a fixed reference to PHP manual
Jan 5, 2023 at 12:19 history edited Your Common Sense CC BY-SA 4.0
using empty() in context of this error makes absolutely no sense
Jan 5, 2023 at 12:03 history edited Your Common Sense CC BY-SA 4.0
Obsoleted suggestions removed. Undefined variable is now a Warning. Also consistent examples. Man it needs a complete rewrite
Jan 5, 2023 at 11:36 history edited Your Common Sense CC BY-SA 4.0
that intro about empty() seems completely off the track. Nobody asked
Feb 24, 2022 at 13:02 history edited IMSoP CC BY-SA 4.0
eugh; markdown is the worst
Jul 8, 2021 at 14:18 comment added Tristanisginger i'm a huge fan of the null coalesce operator
S May 21, 2019 at 17:53 history suggested Dev_NIX CC BY-SA 4.0
There are more values considered as falsy by the function empty
May 21, 2019 at 15:56 review Suggested edits
S May 21, 2019 at 17:53
May 18, 2019 at 23:20 comment added TheKeymaster PHP now also has the ?? operator which does (from PHP documentation): "It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.", which is exactly what you need in most cases.
May 25, 2018 at 18:40 history edited AbraCadaver CC BY-SA 4.0
deleted 31 characters in body
Apr 3, 2018 at 12:49 comment added deEr. “This means that you could use only empty() to determine if the variable is set, and in addition it checks the variable against the following, 0,"",null.” Is incomplete. It also checks against "0".
Jun 29, 2017 at 2:09 comment added ZenithS We can also use $_REQUEST += ['my_index' => null, '...' => null]; to fulfill missing indexes before usages. In-case that you already know the index keys.
May 23, 2017 at 12:10 history edited URL Rewriter Bot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
May 19, 2017 at 20:55 history edited Nisse Engström CC BY-SA 3.0
Broke up blockquote into 3 parts. Second part is quoted from a different page. Third part doesn't appear to be quoted from anywhere. Formatted quote according to original. Edited code so it actually compares the two results. Moved code to site that maps URL to a *single* version of the code.
Apr 7, 2017 at 10:48 history edited glaux CC BY-SA 3.0
Added the null coalesce operator of PHP 7
Nov 25, 2016 at 11:48 history edited user2560539 CC BY-SA 3.0
added 864 characters in body
Nov 17, 2016 at 20:01 comment added M Rostami I don't recommend using isset() for arrays, e.g. $str = '111';, (I know it should be array) isset($str[0]) will return true. It's better off using array_key_exist() instead of isset()
Oct 31, 2016 at 18:22 history edited AbraCadaver CC BY-SA 3.0
added 292 characters in body
Oct 31, 2016 at 18:17 history edited AbraCadaver CC BY-SA 3.0
added 292 characters in body
Aug 23, 2016 at 7:43 history edited Rizier123 CC BY-SA 3.0
added 175 characters in body
May 31, 2016 at 11:58 history edited Rizier123 CC BY-SA 3.0
added 283 characters in body
May 12, 2016 at 7:35 comment added Mugoma J. Okomba Using isset() didn't work for me. But array_key_exists() and @ works
May 10, 2016 at 22:41 history edited Rizier123 CC BY-SA 3.0
added 975 characters in body
Apr 23, 2016 at 7:31 history edited Tomasz CC BY-SA 3.0
Formatting
Dec 18, 2015 at 10:47 history edited kenorb CC BY-SA 3.0
Expanding answer to empty().
Aug 6, 2015 at 9:58 comment added Aycan Yaşıt @twistedpixel Those 4 ways are independent, that's not a 4-step guide. So if you've chosen to use way 4, that means you didn't implement first 3 ways, so you you didn't supress any errors yet.
Feb 9, 2015 at 13:38 comment added forsvunnet Why is it recommended to use 1. $value = isset($_POST['value']) ? $_POST['value'] : ''; instead of using 4. $value = @$_POST['value'];?
Oct 11, 2014 at 14:14 comment added Slava Is it possible to shut-up the message inline (not in handler) when also a custom error handler is used? $var = @$_GET['nonexisting']; still causes notice..
Sep 13, 2014 at 8:09 comment added Salman Arshad Hiding the issues is NOT the way to deal with issues. Items #2...#4 can be used only on production servers, not in general.
Feb 15, 2014 at 20:28 history edited Michael Berkowski CC BY-SA 3.0
added 66 characters in body
Oct 24, 2013 at 20:00 comment added IMSoP @dieselpower44 A couple of thoughts: The "shut-up operator" (@) has some performance issues. Also, since it suppresses all errors within a particular scope, using it without care might mask messages you wish you'd seen.
Jul 14, 2013 at 17:31 history edited Michael Berkowski CC BY-SA 3.0
Removed empty() to avoid confusion
Jul 14, 2013 at 17:26 history edited Michael Berkowski CC BY-SA 3.0
Improved isset/empty
Dec 3, 2012 at 17:08 history edited toxalot CC BY-SA 3.0
Added emphasis to recommendation. Added links to another SO reference question.
Feb 14, 2012 at 6:41 history edited animuson CC BY-SA 3.0
Separated lines a little for better readability.
Jan 23, 2011 at 12:22 vote accept Pekka
Nov 23, 2010 at 22:35 history edited Alin P. CC BY-SA 2.5
added 12 characters in body; added 8 characters in body
Nov 23, 2010 at 22:24 history edited Alin P. CC BY-SA 2.5
deleted 123 characters in body
Nov 23, 2010 at 22:15 history edited Alin P. CC BY-SA 2.5
added 745 characters in body; added 4 characters in body
Nov 23, 2010 at 21:58 history edited Alin P. CC BY-SA 2.5
added 531 characters in body; deleted 61 characters in body
Nov 23, 2010 at 21:52 history made wiki Post Made Community Wiki by Bill the Lizard
Nov 23, 2010 at 21:41 history edited Alin P. CC BY-SA 2.5
added 191 characters in body
Nov 23, 2010 at 21:36 history answered Alin P. CC BY-SA 2.5