What is difference in =, == and === in PHP?

  • = is the assignment operator
  • == is the comparison operator (checks if two variables have equal values)
  • === is the identical comparison operator (checks if two variables have equal values and are of the same type).
$a = $b Assign Sets $a to be equal to $b. $a == $b Equal TRUE if $a is equal to $b. $a === $b Identical TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

For more detail about == and === read doc from php.net

 


What is the maximum length of a table name, a database name, or a field name in mysql?

  • Database name: 64 characters
  • Table name: 64 characters
  • Column name: 64 characters

How many ways we can pass the variable through the navigation between the pages?

At least 3 ways:

  1. Put the variable into session in the first page, and get it back from session in the next page.
  2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.
  3. Put the variable into a hidden form field, and get it back from the form in the next page.

How Many Ways I Can Redirect A Php Page?

Here are the possible ways of php page redirection.

  1. Using Java script:
    '; echo 'window.location.href="'.$filename.'";'; echo ''; echo ''; echo ''; echo ''; } }
    redirect
  2. Using php function: header

What's The Special Meaning Of __sleep And __wakeup?

__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

What is the purpose of _METHOD_ constant?

_METHOD_ − The class method name.


What is the purpose of _CLASS_ constant?

_CLASS_ − The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.


What is the purpose of _FUNCTION_ constant?

_FUNCTION_ − The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.


What is the purpose of _FILE_ constant?

_FILE_ − The full path and filename of the file. If used inside an include,the name of the included file is returned. Since PHP 4.0.2, _FILE_ always contains an absolute path whereas in older versions it contained relative path under some circumstances.


What is the purpose of _LINE_ constant?

_LINE_ − The current line number of the file.


How will you redirect a page using PHP?

The PHP header() function supplies raw HTTP headers to the browser and can be used to redirect it to another location. The redirection script should be at the very top of the page to prevent any other part of the page from loading.

function redirect($url) {
    ob_start();
    header('Location: '.$url);
    ob_end_flush();
    die();
}

How will you destroy the session?

A PHP session can be destroyed by session_destroy() function.

What is the purpose of $_PHP_SELF variable in PHP?

$_PHP_SELF − A string containing PHP script file name in which it is called.

What is preg_match() function in PHP?

preg_match() - The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.

What are interfaces in PHP?

Interfaces are defined to provide a common function names to the implementors. Different implementors can implement those interfaces according to their requirements. You can say, interfaces are skeltons which are implemented by developers.

What is the use of final keyword?

The final keyword prevents child classes from overriding a method by prefixing the definition with final. If the class is defined as final then it cannot be extended.

What is the difference between Session and Cookie?

The main difference between session and cookie is that sessions are stored on the server, and cookies are stored on the user's computers in the text file format. Cookies can't hold multiple variable while session can hold multiple variables..We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking


What is PHP?

PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can cretae sites using its CMS.WordPress,osCommerce are the famus CMS of php.It is also an object oriented programming language like java,C-sharp etc.


What are the __construct() and __destruct() methods in a PHP class?

All objects in PHP have Constructor and Destructor methods built-in. The Constructor method is called immediately after a new instance of the class is being created, and it’s used to initialize class properties. The Destructor method takes no parameters.

Understanding these two in PHP means that the candidate knows the very basics of OOP in PHP.


How can you enable error reporting in PHP?

Check if display_errors is equal on in the php.ini or declare “ini_set('display_errors', 1)” in your script.
Then, include “error_reporting(E_ALL)” in your code to display all types of error messages during the script execution.

Enabling error messages is very important especially during the debugging process as one can instantly get the exact line that is producing the error and can see also if the script in general is behaving correctly.


Back to Top