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
5
votes
2 answers

php isset() on a string variable using a string as index

I have some strange issue with isset() function in PHP. Let me show... . array( 'index' => 'Główna' ), 'dodaj' => 'Dodaj ogłoszenie', ); var_dump( isset($aTestArray['index']) ); var_dump(…
BlueMan
  • 687
  • 2
  • 10
  • 23
5
votes
8 answers

Why does in_array() not work on $_POST?

I'm trying to check that user's submitted data, from $_POST, has at least the same elements that my passed array has. I'm doing it because I will use those elements later by calling $_POST['element'] and I don't like errors about that element…
daGrevis
  • 21,014
  • 37
  • 100
  • 139
5
votes
4 answers

Is $_SERVER['SERVER_ADDR'] always set?

Is $_SERVER['SERVER_ADDR'] always set? Should I check with isset() or is that unnecessary? I need to get the IP of the site so I can find out if it's 127.0.0.1/localhost
Nick
  • 53
  • 1
  • 3
5
votes
7 answers

Using Isset with native sessions in CodeIgniter

I've read about how CI handles sessions differently than native sessions and feel slightly insecure about storing all the data in a cookie(?), unlike PHP's native session which only stores the session ID(?). So I've decided to use native sessions…
Millenille
  • 51
  • 1
  • 2
5
votes
1 answer

Possibly-undefined argument to PHP function

In displaying values retrieved from a database, values that may or may not exist, my PHP code has a lot of this: if ( isset( $data['a'] ) ) $a = number_format( $data['a'] ); else $a = '–'; if ( isset( $data['b'] ) ) $b = number_format(…
sidbushes
  • 301
  • 1
  • 10
5
votes
4 answers

PHP isset($this) and using the same object method in a static and object context

I'm working on a class which needs to be accessible via static function calls as well as object methods. One thing I have found is that I'm duplicating logic across multiple functions. Simplified example: class Configurable{ protected…
Rowan
  • 5,597
  • 2
  • 22
  • 32
5
votes
3 answers

Undefined index even with isset

although i used if(isset()) still get Notice: Undefined index: user_name in C:\xampp\htdocs\www\jq\182-186 Users online sample application\users.php here is part of PHP code if (isset($_POST['user_name'] , $_POST['action']) ||…
MJ1
  • 81
  • 6
4
votes
5 answers

How to check if input type button is pressed in PHP?

The isset() function can be used to check if the input type submit is pressed, but is there a way to check if the input type button is pressed? In my code the button does nothing but call a function on the .Onclick() event which then refreshes the…
Parth Mody
  • 438
  • 1
  • 5
  • 17
4
votes
4 answers

Should I declare and check if variables exist in PHP?

I've noticed on XAMPP that strict error reporting is on and I get undefined index errors now. I just have two small questions (I'm still learning here): I know you don't have to declare variables in PHP but is there any advantage to declaring them…
David Zorychta
  • 13,039
  • 6
  • 45
  • 81
4
votes
2 answers

PHP:isset() returns false for object's dynamic properties

I have a heirarchy of classes that get initialized from a database. I am using __get() and __set() with an array in a common Item base class to support different numbers of properties. One class derived from Item, UserProfile is used to store user…
Sinthia V
  • 2,103
  • 2
  • 18
  • 36
4
votes
4 answers

PHP creating a new object or use existing one if isset?

Many times i find this redundant: $found = $repo->findOneByCode($code); $zone = isset($found) ? $found : new Zone(); Can anyone suggest a better way, similar to (not working): $zone = $repo->findOneByCode($code) || new Zone(); EDIT: i can't modify…
gremo
  • 47,186
  • 75
  • 257
  • 421
4
votes
2 answers

Can I hide PHP Warning: Undefined array key without suppressing all other warnings?

So, looks like they changed the way accessing an array with an unknown key raises a message.
Jack
  • 1,488
  • 11
  • 21
4
votes
1 answer

PHP 5.6: ArrayAccess: Function isset calls offsetGet and causes undefined index notice

I wrote simple PHP class that implements ArrayAccess Interface: class MyArray implements ArrayAccess { public $value; public function __construct($value = null) { $this->value = $value; } public function…
Filip Š
  • 746
  • 2
  • 13
  • 22
4
votes
3 answers

Using ISSET with checkboxes

I am working on a wordpress search form to refine the current search and what Im trying to do is have the search results page with the search from and it's values set based on the query. So far I've been successful in doing so with single select…
730wavy
  • 944
  • 1
  • 19
  • 57
4
votes
1 answer

How does isset not throw an error when evaluating array properties?

Whenever I try to access a property of an array that does not exist, php throws an ERROR_NOTICE that reads like this: Notice: Undefined offset: BLANK in BLANK on line BLANK $a = array("a","b","c"); $a[4]; //throws an error Instead, if I use isset…
Nicola Pedretti
  • 4,831
  • 3
  • 36
  • 42