Basic Input Testing in PHP
- PHP
provides various Testing Functions for Basic Input Testing.
- These functions are very important for professional development.
- If the program is used without checking the value, then somewhere the program crashes and the project fails, and impossible to find a bug.
- PHP functions provide to test the value of any kind of Data Type Identifier i.e. Variable at any time are very important functions.
Basically, all
Testing Functions always return a Boolean value.
isset()
function
- This Function accepts Mixed Type Variables with the Number of Arguments.
- This function checks that the specified variables as arguments are set to a value and are not NULL.
- If the specified variable as an argument is set to a value other than NULL, then this function returns true otherwise it returns False.
empty()
Language Construct
- This function tests whether the specified variable as an argument is Empty or not.
- It works in the Exact Opposite way of Function (boolean)$var Expression.
array() (to
Empty Array)
- Declared but Uninitialized/Unassigned Data Member in a Class.
- The basic
difference between both empty() and isset() is that empty() checks whether the
values which are
considered Empty in PHP are stored in the variable other than those Empty
Values or not.
unset()
Function
- This Function accepts a Variable Number of Arguments as Arguments.
- The main work of this function is to destroy the specified variable in the form of an Argument.
- When unset() a Global Variable inside a Function, then that Variable is unset only inside that Function, and remains available outside the Function. That is, Destroying Local variables and Global variables.
- To Destroy Global Variable, use Unset that Variable from $GLOBAL Array, which is Destroy Permanently from our script.
- If pass a reference to a variable in a function and unset that variable in that function, then that variable is destroyed only for the function.
- That function is still available outside the function.
- When unset a Static Variable inside a Function, then that Static Variable is also Destroy only for that Function.
- If the __unset () magic method is defined and calls the unset() function for an inaccessible object property, then this magic method gets called automatically.
is_ Functions
- Used to test the variables of different data types whether they belong to that data type or not.
- The different is_ functions are as follows:
is_array()
Function
The is_array() function checks
whether a variable is an array or not. This function returns true (1) if
the variable is an array, otherwise, it returns false/nothing.
is_double()
Function
The is_double() function checks
whether a variable is of type float or not. This function is an alias of
is_float().
is_float()
Function
The is_float() function checks
whether a variable is of type float or not. This function returns true (1)
if the variable is of type float, otherwise, it returns false.
is_int()
Function
The is_int() function checks whether a variable is of type integer
or not.
This function returns true (1) if the variable is of type integer,
otherwise, it returns false.
is_null()
Function
The is_null() function checks
whether a variable is NULL or not. This function returns true (1) if the
variable is NULL, otherwise, it returns false/nothing.
is_object()
Function
The is_object() function checks
whether a variable is an object. This function returns true (1) if the
variable is an object, otherwise, it returns false/nothing.
is_string()
Function
The is_string() function checks
whether a variable is of type string or not. This function returns true (1)
if the variable is of type string, otherwise, it returns false/nothing.
is_callable()
Function
The is_callable() function checks
whether the contents of a variable can be called a function or not. This
function returns true (1) if the variable is callable, otherwise, it returns
false/nothing.
- Allows sending a raw HTTP header. It is useful for handling security problems and access restrictions.
- In this instance, it redirects the user to the specified page.
- A very common error with beginning PHP users is that they fail to understand a fact: Once sent, the headers cannot be sent again.
- This means that any echo, any space, or any tabulation left before the call to the header function will trigger a warning in the script execution.
0 Comments