Questions tagged [isset]

Determine if a variable is set and is not NULL

Description [source: https://php.net/manual/en/function.isset.php]

bool isset (mixed$var [,mixed$... ] )

Determine if a variable is set and is not NULL.

If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

1015 questions
27
votes
2 answers

Check if array value isset and is null

How to check if array variable $a = array('a'=>1, 'c'=>null); is set and is null. function check($array, $key) { if (isset($array[$key])) { if (is_null($array[$key])) { echo $key . ' is null'; } echo $key . '…
Bartek Kosa
  • 842
  • 1
  • 14
  • 25
25
votes
7 answers

PHP check if False or Null

I also get confused how to check if a variable is false/null when returned from a function. When to use empty() and when to use isset() to check the condition ?
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
24
votes
4 answers

Why is array_key_exists 1000x slower than isset on referenced arrays?

I have found that array_key_exists is over 1000x slower than isset at check if a key is set in an array reference. Does anyone that has an understanding of how PHP is implemented explain why this is true? EDIT: I've added another case that seems to…
Kendall Hopkins
  • 43,213
  • 17
  • 66
  • 89
24
votes
6 answers

Is empty() enough or use isset()?

Note - I know pretty much about empty() and isset(), what I am asking is the most proper/efficient way of using them. I've just saw at php.net this sentence under empty() reference: No warning is generated if the variable does not exist. That…
Forien
  • 2,712
  • 2
  • 13
  • 30
24
votes
3 answers

Will isset() return false if I assign NULL to a variable?

I mean... I "set" it to NULL. So isset($somethingNULL) == true?
openfrog
  • 40,201
  • 65
  • 225
  • 373
24
votes
7 answers

How to tell whether a variable has been initialized in C#?

I know this is a dumb question and I guess it must have been asked before. However I am unable to find an answer to my question. Here is some sample code (which of course does not compile) to outline my problem: class test { int[] val1; …
niklasfi
  • 15,245
  • 7
  • 40
  • 54
20
votes
3 answers

How do I check whether an environment variable is set in PHP?

In PHP, how do I test whether an environment variable is set? I would like behavior like this: // Assuming MYVAR isn't defined yet. isset(MYVAR); // returns false putenv("MYVAR=foobar"); isset(MYVAR); // returns true
wecsam
  • 2,651
  • 4
  • 25
  • 46
18
votes
3 answers

Isset expression error

I have basically coded a code which populates a list of categories from my database then you are able to select which to delete. I have the issue with the delete code which does not seem to work due to the error: Fatal error: Cannot use isset() on…
user3411002
  • 783
  • 3
  • 9
  • 27
15
votes
7 answers

Check if variable is_undefined in PHP

In PHP, I want to check if a variable has not been set/defined, where setting a variable NULL is considered set/defined. I'm aware everything here: http://php.net/manual/en/types.comparisons.php including isset(), empty(), and is_null(). None of…
tjbourke
  • 221
  • 1
  • 2
  • 8
15
votes
2 answers

Check if a property exists on magically set properties

There is a lot of SO questions about the subject, notably this one, but it does not help me. There is an ambiguity between property_exists and isset so before asking my question, I'm going to pointing it out: property_exists property_exists checks…
Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153
15
votes
4 answers

How do I check if a $_GET parameter exists but has no value?

I want to check if the app parameter exists in the URL, but has no value. Example: my_url.php?app I tried isset() and empty(), but don’t work. I’ve seen it done before and I forgot how.
Ben
  • 5,627
  • 9
  • 35
  • 49
14
votes
3 answers

PHP Error : Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

I am using PHP 7.4 for a laravel application and I am getting this exception very frequently. ErrorException (E_DEPRECATED) Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` The code which…
humbleiam
  • 969
  • 2
  • 12
  • 34
14
votes
11 answers

How to solve the missing object properties in PHP?

This is a bit philosophical but I think many people encountered this problem. The goal is to access various (dynamically declared) properties in PHP and get rid of notices when they are not set. Why not to __get? That's good option if you can…
Pavel S.
  • 11,892
  • 18
  • 75
  • 113
13
votes
9 answers

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

I have a little problem with my if(isset($_POST['submit'])) code. What I want is some echos and a table to not appear when the script is open but I do want it to show when the submit button for the form has been clicked. The problem is though that…
BruceyBandit
  • 3,978
  • 19
  • 72
  • 144
13
votes
8 answers

PHP Shorthand for isset form POST value

I am creating a form and am just looking for more efficient ways to do things. What I have so far is:

So some of them will…
Drew
  • 6,736
  • 17
  • 64
  • 96
1
2
3
67 68