Home > Software design >  Does the server call "isset" all the time?
Does the server call "isset" all the time?

Time:10-07

I've got some code which looks like this:

<?php


if (isset($_POST['username'],$_POST['first_name'],$_POST['surname'], $_POST['email'], $_POST['p'])) {
    // Sanitize and validate the data passed in...

in a file called register.inc.php. The only references to this file are

include_once 'includes/register.inc.php';

in the opening lines of a couple of other files.

What is puzzling is just how the php condition gets called. Is it called continuously, so that as soon as the variables have been set, it triggers? Or is it called when the page that includes it is loaded? Whatever, it doesn't seem to be called like a normal function. It all seems a bit mysterious and unexplained. Can anyone help me out?

Thanks.

CodePudding user response:

It is only called whenever it is called. If it's at the beginning of the file, then yes, it'll be called at the location where the file is included (at the location of the include_once call, in that case). It only performs the check once, returning true if, at the time it is called, all the variables exist (are set), false otherwise.

CodePudding user response:

This might help you further learning PHP.

a = array ('test' => 1, 'hello' => NULL, 'pie' => array('a' => 'apple'));

var_dump(isset($a['test']));            // TRUE
var_dump(isset($a['foo']));             // FALSE
var_dump(isset($a['hello']));           // FALSE

The above exactly explains how the isset() function can be used. If you are unsure how a PHP function works or looking for a new one, try to search the function on [https://www.php.net/][1] if you type your function here you'll be directed to the corresponding page.

  •  Tags:  
  • php
  • Related