Differentiate Between Variables and Constants in PHP
Differentiate Between Variables and Constants in PHP
Few difference between variables and constants in PHP are given below:
Variables Constants
The value of a variable can be The constant value can’t be changed during script
changed during the execution. execution.
Variables require compulsory usage No dollar sign ($) is required before using a
of the $ sign at the start. constant.
It is possible to define a variable by Constants can’t be defined by simple assignments.
simple assignment. They are defined using the define() function.
The default scope is the current Constants can be accessed throughout without any
access scope. scoping rules.
When you work with an application, you open it, do some modifications, and then you
close it. This is much like a Session. The computer knows who you are. It knows when
the application is started and ended by you.
But on the internet, the webserver does not know who you are or what you do, because
the HTTP address doesn’t maintain a state. This problem is solved using session
variables by storing user information to be used across multiple pages (e.g. username,
favorite color, etc).
By default, session variables will last until the user closes the browser.
So Session variables hold single user information and are available to all pages in one
application.
PEAR provides a higher level of programming for web developers. It contains all kinds of
PHP code snippets and libraries. It also provides you with a command-line interface to
automatically install packages.
The main difference between echo and print in PHP are given
below:
echo print
If you want to pass more than one parameter to echo, a Use of parenthesis is not required with
parenthesis should be used. the argument list.
This interaction helps bridge the gaps and use the best of
both languages.
11. What is the purpose of @ in PHP?
You can parse PHP code with PHP using the token_get_all()
function.
13. What are the different types of Array in PHP?
Indexed Array
Associative Array
Multidimensional Array
18. What is the most used method for hashing passwords in PHP?
include() function
This function is used to copy all the contents of a file called
within the function, text wise into a file from which it is called.
require() function:
Example:
setcookie(“instrument_selected”, “guitar”)
21. What is the difference between ASP.NET and PHP?
It has a license cost associated with it. PHP is open-source and freely available.
25. What are the steps to create a new database using MySQL and PHP?
Syntax:
session_start();
The session_destroy() function is used to destroy all of the
session variables as given below:
<?php
session_start();
session_destroy();
?>
The term cURL stands for client-side URL. cURL make use of
libcurl(client-side URL Transfer Library) which supports many
protocols like FTP, FTPS, HTTP/1, HTTP POST, HTTP PUT,
HTTP proxy, HTTPS, IMAP, Kerberos etc. It allows you to
connect to a URL and retrieve and display information from
that page – like the HTML content of the page, HTTP headers,
and their associated data, etc.
Steps for connecting with URL using PHP cURL POST are
given below:
The above code will accept the GET request and return
output in the JSON format.
Output File
It can be used for submitting the form where Submissions by form with POST cannot be
the user can bookmark the result. bookmarked.
GET method is not safer since parameters may POST method is safer than GET because the
be stored in web server logs or browser parameters are not stored in web server logs or
history. browser history.
Example usage:
//sendEmail() function argument $email is type hinted of Email Class. It
means to call this function you must have to pass an email object otherwise
an error is generated.
<?php
function sendEmail (Email $email)
{
$email->send();
}
?>
Syntax: exit(message)
Example: The code given below will print a message and exit
the current script.
<?php
$site = "https://www.interviewbit.com//";
fopen($site,"r")
or exit("Unable to connect to $site");
?>
Conclusion