Home » Job Interview » PHP Interview questions

PHP Interview questions

1:What is the value of $b in the following code?

$a="5 USD";
$b=10+$a;
echo $b;

Ans:15

2:What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?

In the get method the data made available to the action page
( where data is received ) by the URL so data can be seen in the address bar.
Not advisable if you are sending login info like password etc.

In the post method the data will be available as data blocks
and not as query string.

3:What is GPC?

G – Get
P – Post
C – Cookies

4:What are super global arrays?

All variables that come into PHP arrive inside one of several special
arrays known collectively as the superglobals. They're called
superglobal because they are available everywhere in your script, even
inside classes and functions.

5:Give some example for super global arrays?

 $GLOBALS
 $_GET
 $_POST
 $_SESSION
 $_COOKIE
 $_REQUEST
 $_ENV
 $_SERVER

6:What’s the difference between COPY OF A FILE & MOVE_UPLOAD_FILE in file uploading?

MOVE_UPLOAD_FILE : This function checks to ensure that the file
designated by filename is a valid upload file (meaning that it was
uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it
 will be moved to the filename given by destination.
 If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
 Copy :Makes a copy of a file. Returns TRUE if the copy succeeded, FALSE otherwise.

7:When I do the following, the output is printed in the wrong order:

function myfunc($argument) {
 echo $argument + 10;
 }
 $variable = 10;
 echo "myfunc($variable) = " . myfunc($variable);
<pre>What's going on?
 To be able to use the results of your function in an expression (such as concatenating it with other strings in the example above), you need to return the
 value, not echo it.

8:What are the Formatting and Printing Strings available in PHP?


Function Description
 printf() : Displays a formatted string
 sprintf() : Saves a formatted string in a variable
 fprintf() : Prints a formatted string to a file
 number_format() : Formats numbers as strings

9:Explain the types of string comparision function in PHP.


Function Descriptions
 strcmp() :Compares two strings (case sensitive)
 strcasecmp() :Compares two strings (not case sensitive)
 strnatcmp(str1, str2) :Compares two strings in ASCII order, but
 any numbers are compared numerically
 strnatcasecmp(str1, str2):Compares two strings in ASCII order,
 case insensitive, numbers as numbers
 strncasecomp() : Compares two strings (not case sensitive)
 and allows you to specify how many characters
 to compare
 strspn() : Compares a string against characters represented
 by a mask
 strcspn() : Compares a string that contains characters not in
 the mask

10:Explain soundex() and metaphone().

soundex()
 The soundex() function calculates the soundex key of a
string. A soundex key is a four character long alphanumeric string that
represent English pronunciation of a word. he soundex() function can be
used for spelling applications.
 $str = "hello";
 echo soundex($str);
 ?>
 metaphone()
 The metaphone() function calculates the metaphone key of a string. A
metaphone key represents how a string sounds if said by an English
speaking person. The metaphone() function can be used for spelling
applications.
 echo metaphone("world");
 ?>

11:What do you mean range()?

Starting from a low value and going to a high value, the range()
function creates an array of consecutive integer or character values. It
 takes up to three arguments: a starting value, an ending value, and an
increment value. If only two arguments are given, the increment value
defaults to 1.
 Example :
 echo range(1,10); // Returns 1,2,3,4,5,6,7,8,9,10
 ?>

12:How to read and display a HTML source from the website url?

$filename="http://www.kaptivate.in/";
 $fh=fopen("$filename", "r");
 while( !feof($fh) ){
 $contents=htmlspecialchars(fgets($fh, 1024));
 print "

$contents

";
 }
 fclose($fh);
 ?>

13:What is properties of class?

Class member variables are called "properties". We may also see them
referred to using other terms such as "attributes" or "fields", but for
the purposes of this reference we will use "properties". They are
defined by using one of the keywords public, protected, or private,
followed by a normal variable declaration. This declaration may include
an initialization, but this initialization must be a constant value that
 is, it must be able to be evaluated at compile time and must not depend
 on run-time information in order to be evaluated.

14:How to use HTTP Headers inside PHP? Write the statement through which it can be added?

HTTP headers can be used in PHP by redirection which is written as:

The headers can be added to HTTP response in PHP using the header(). The
 response headers are sent before any actual response being sent. The
HTTP headers have to be sent before taking the output of any data. The
statement above gets included at the top of the script.

15:Why we used PHP?

Because of several main reason we have to use PHP. These are:
 1.PHP runs on many different platforms like that Unix,Linux and Windows etc.
 2.It codes and software are free and easy to download.
 3.It is secure because user can only aware about output doesn't know how that comes.
 4.It is fast,flexible and reliable.
 5.It supports many servers like: Apache,IIS etc.

16:Arrays in PHP?

Create array in PHP to solved out the problem of writing same variable
name many time.In this we create a array of variable name and enter the
similar variables in terms of element.Each element in array has a unique
 key.Using that key we can easily access the wanted element.Arrays are
essential for storing, managing and operating on sets of variables
effectively. Array are of three types:
 1.Numeric array
 2.Associative array
 3.Multidimensional array
 Numeric array is used to create an array with a unique key.Associative
array is used to create an array where each unique key is associated
with their value.Multidimensional array is used when we declare multiple
 arrays in an array.

17:What is foreach loop in php?

foreach:Uses, When When we want execute a block of code for each element in an array.
 Syntax:
 foreach (array as value)
 {
 code will be executed;
 }
 eg:
 $arr=array("one", "two", "three");
 foreach ($arr as $value)
 {
 echo "Value: " . $value . "
 ";
 }
 ?>

18:How we used $_get and $_post variable in PHP?

We know that when we use $_GET variable all data_values are display on
our URL.So,using this we don't have to send secret data (Like:password,
account code).But using we can bookmarked the importpage.
 We use
$_POST variable when we want to send data_values without display on
URL.And their is no limit to send particular amount of character.
 Using this we can not bookmarked the page.

19:Why we use $_REQUEST variable?

We use $_REQUEST variable in PHP to collect the data_values from $_GET,$_POST and $_COOKIE variable.
 Example:
 R4R Welcomes You .

You are years old!

20:How we handle errors in PHP?Explain it?

In PHP we can handle errors easily.Because when error comes it gives error line with their respective line and send error message to the web browser.
 When we creating any web application and scripts. We should handle errors wisely.Because when this not handle properly it can make bg hole in security.
 In PHP we handle errors by using these methods:
 1.Simple "die()" statements
 2.Custom errors and error triggers
 3.Error reporting

21: How we use Custom errors and error triggers error handling method in PHP?

In Custom errors and error triggers,we handle errors by
 using self made functions.
 1.Custom errors : By using this can handle the multiple
 errors that gives multiple message.
 Syntax:
 set_error_handler(\\\"Custom_Error\\\");
 In this syntax if we want that our error handle, handle
 only one error than we write only one argument otherwise
 for handle multiple errors we can write multiple arguments.

Example:
 //function made to handle errorfunction
 custom_Error($errorno, $errorstr)
 {
 echo \\\"Error: [$errorno] $errorstr\\\"; }
 //set error handler like that
 set_error_handler(\\\"custom_Error\\\");
 //trigger to that error
 echo($verify);?>

2.error trigger : In PHP we use error trigger to handle
 those kind of error when user enter some input data.If
 data has an error than handle by error trigger function.
 Syntax:

$i=0;if ($i<=1) { trigger_error(\\\"I should be greater than 1 \\\"); } ?>
 In this trigger_error function generate error when i is
 less than or greater than 1.

22:What do you understand about Exception Handling in PHP?

In PHP 5 we introduce a Exception handle to handle run time exception.It is used to change the normal flow of the code execution if a specified error condition occurs.
 An exception can be thrown, and caught("catched") within PHP. Write code in try block,Each try must have at least one catch block. Multiple catch blocks can be used to catch different classes of exceptions.
 Some error handler methods given below:
 1.Basic use of Exceptions
 2.Creating a custom exception handler
 3.Multiple exceptions
 4.Re-throwing an exception
 5.Setting a top level exception handler

23: What is the difference b/n ‘action’ and ‘target’ in form tag?

Action:
 Action attribute specifies where to send the form-data when
 a form is submitted.
 Syntax:
 Example:
 action="formValidation.php">
 Target:
 The target attribute specifies where to open the action URL.
 Syntax:
 Value:
 _blank – open in new window
 _self- Open in the same frame as it was clicked
 _parent- Open in the parent frameset
 _top- Open in the full body of the window
 Framename- Open in a named frame

24:What do you understand about PHP accelerator ?

Basically PHP accelerator is used to boost up the performance of PHP programing language.We use PHP accelerator to reduce the server load and also use to enhance the performance of PHP code near about 2-10 times.In one word we can say that PHP accelertator is code optimization technique.

26:How we use ceil() and floor() function in PHP?

ceil() is use to find nearest maximum values of passing value.
 Example:
 $var=6.5;
 $ans_var=ceil($var);
 echo $ans_var;
 Output:
 7
 floor() is use to find nearest minimum values of passing value.
 Example:
 $var=6.5
 $ans_var=floor($var);
 echo $ans_var;
 Output:
 6

27:What is the answer of following code

echo 1< 2 and echo 1 >2 ?Output of the given code are given below:
 echo 12
 output: no output

28: What is the difference b/w isset and empty?

The main difference b/w isset and empty are given below:
 isset: This variable is used to handle functions and checked a variable is set even through it is empty.
 empty: This variable is used to handle functions and checked either variable has a value or it is an empty string,zero0 or not set at all.

1. What is the difference between a static and Dynamic Web site?


A static website is one that is written in HTML only. Each page is a 
separate document and there is no database that it draws on. What this 
means functionally is that the only way to edit the site is to go into 
each page and edit the HTML - So you would have to do it yourself using a
 web page editor such as FrontPage or Dreamweaver, or pay your web 
developer to make updates for you.

A dynamic website is created by
 webdevelopers who are strong in ASP.Net, PHP, JAVA and more... This 
website pages contains data is retrieved from certain database. Each 
time the viewer entering a page, the contents of that page is retrieved 
from the database. The administrator can change the content and images 
from admin panel. This is one that changes or customizes itself 
frequently and automatically.

2.What is the meaning of Open Source Software?

Open-Source Software (OSS) is computer software that is available in 
source code form: the source code and certain other rights normally 
reserved for copyright holders are provided under a software license 
that permits users to study, change, improve and at times also to 
distribute the software.Open Source Software means it is a free software
 and no need to buy, we can use full functionallities from this software
 with certain Terms & Conditions. This license allows modifications 
and derived works, and allows us to be distributed under the same terms 
as the license of the original software.

3.Why was PHP developed, what it is used for, and where can you get it?

PHP developed for less script, time saving, Free Open Source Software
 and runs on different platforms such as Windows, Linux, Unix, etc. PHP 
compatible with almost all servers used today such as Apache, IIS, etc.

The
 PHP scripting language resembles JavaScript, Java, and Perl, These 
languages all share a common ancestor, the C programming language. PHP 
has full access to the information that the server has, and very little 
access to information that the client has. In fact, it only has 
information that the client tells the server and that the server passes 
on to PHP. Because it is on the server, however, PHP cannot be modified 
by the client. While you cannot necessarily trust the information that 
the client gives to PHP, you can trust that your PHP is doing what you 
told it to do. Because PHP is on the server end, your PHP scripts can 
affect your server -- such as by keeping an activity log or updating a 
database.

PHP is free dowload from the offical PHP resource
 Download : http://windows.php.net/download/

4.What are the benefits of using PHP and MySQL?

One of the main reasons that businesses choose PHP is its simplicity 
and ease of use. PHP competes against a number of other web scripting 
solutions such as Active Server Pages and PERL, but none of these 
languages are as easy to learn as PHP. Further, some languages require a
 moderate amount of programming background before a developer can get up
 to speed in development. With PHP, however, even non-programmers have 
been able to develop web-based solutions within a matter of days after 
going through the basic tutorials on PHP. PHP commands are simply 
embedded into the same web page with HTML commands, and execute on the 
server to deliver the web pages to the user.

Another big advantage
 of PHP is its interoperability with multiple operating systems. A 
company can use PHP with either Linux, Windows or Macs for example. They
 can also use PHP with the popular open source Apache server. Compare 
that with Microsoft’s Active Server Pages, by contrast, which is 
primarily designed for Microsoft-enabled servers. Portability is 
becoming a chief concern for businesses that use one or more operating 
systems in their businesses. Businesses save money by using PHP to 
leverage their existing I.S. resources rather than investing large sums 
of money to purchase proprietary products.

1. What is PHP?


PHP stand for Hypertext Preprocessor.
 PHP is a Server Side Scripting Language.
 PHP is a Open Source Software.
 PHP free to download and use.
 PHP scripts are executed on server.
 PHP supports many databases such as MYSQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.,

PHP
 development began in 1994 when the Danish/Greenlandic programmer Rasmus
 Lerdorf initially created a set of Perl scripts he called "Personal 
Home Page Tools" to maintain his personal homepage. Marco Tabini is the 
funder an publisher of PHP|architech.

2. What are the method available in form submitting?

GET and POST.

3. What are the differences between GET and POST methods in form submitting?

On the server side, the main difference between GET and POST is where 
the submitted is stored. The $_GET array stores data submitted by the 
GET method. The $_POST array stores data submitted by the POST method.

On the browser side, the difference is that data submitted by the GET
 method will be displayed in the browser’s address field. Data submitted
 by the POST method will not be displayed anywhere on the browser.
GET method is mostly used for submitting a small amount and less sensitive data.
 POST method is mostly used for submitting a large amount or sensitive data.

 

 

 

4. How can we submit from without a submit button?

We can use a simple JavaScript code linked to an event trigger of any 
form field. In the JavaScript code, we can call the 
document.form.submit(); function to submit the form.

5. How can we get the browser properties using php?

echo $_SERVER['HTTP_USER_AGENT'] . “\n\n”;
 $browser = get_browser(null, true);
 print_r($browser);

 

 

6. What Is a Session?

A session is a logical object created by the PHP engine to allow you to 
preserve data across subsequent HTTP requests. Sessions are commonly 
used to store temporary data to allow multiple PHP pages to offer a 
complete functional transaction for the same visitor.

7. How can we register the variables into a session?

 

echo $_SERVER['HTTP_USER_AGENT'] . “\n\n”;
 $browser = get_browser(null, true);
 print_r($browser);

 

 

8. How do you destroy a particular or all Sessions?
unset($_SESSION['shape']);

session_unset();
session_destroy();


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

Register the variable into the session
 Pass the variable as a cookie
 Pass the variable as part of the URL

10. What are the different functions in sorting an array?

asort()
 arsort()
 ksort()
 krsort()
 uksort()
 sort()
 natsort()
 rsort()

11. How can we know the total number of elements of Array?

sizeof($array_var)
 count($array_var)

If we just pass a simple var instead of a an array it will return 1.

12. What type of headers that PHP supports?

$_SERVER[‘HTTP_ACCEPT’]

13. How can we extract string ‘abc.com’ from a string ‘http://info@abc.com’ using regular_expression of php?

We can use the preg_match() function with “/.*@(.*)$/” as the regular expression pattern.
 For example:

14. How can we create a database using php?

mysql_create_db();

15. Explain include(), include_once, require() and require_once.

include()
 The include() function takes all the content in a specified file and includes it in the current file. If an error occurs, the include() function generates a warning, but the script will continue execution.

include_once()
 File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once().

require()
 The require() function is identical to include(), except that it handles errors differently. The require() generates a fatal error, and the script will stop.

require_once()
 The required file is called only once when a page is open and further calling of the file will be ignored.

16. What are the different types of errors in php?


Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behaviour.
 Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
 Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behaviour is to display them to the user when they take place.

If we just pass a simple var instead of a an array it will return 1.

 

17. What are the Formatting and Printing Strings available in PHP?

Function Description
 printf() Displays a formatted string
 sprintf() Saves a formatted string in a variable
 fprintf() Prints a formatted string to a file
 number_format() Formats numbers as strings

18. How to find a length of a string?

strlen()

19. What is the functionality of the function strstr and stristr?

strstr() returns part of a given string from the first occurrence of a given substring to the end of the string.
 For example:
 strstr("user@example.com","@") will return "@example.com".stristr() is idential to strstr() except that it is case insensitive.

20. How can we get second of the current time using date function?

echo data('s', time())

21. What is the difference between the functions unlink and unset?

unlink() deletes the given file from the file system.
 unset() makes a variable undefined.

22. What is the difference between ereg_replace() and eregi_replace()?

eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.

23. What is the difference between characters \023 and \x23?

The first one is octal 23, the second is hex 23.

24. What is the difference between PHP4 and PHP5?

PHP4 cannot support oops concepts and Zend engine 1 is used.PHP5 supports oops concepts and Zend engine 2 is used. Error supporting is increased in PHP5. XML and SQLLite will is increased in PHP5.

25. What are the differences between mysql_fetch_array(), mysql_fetch_object(),


mysql_fetch_row()?
 mysql_fetch_array:
 Fetch a result row as an associative array and a numeric array.

mysql_fetch_object:
 Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.

mysql_fetch_row():
 Fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

26. In how many ways we can retrieve data in the result set of MYSQL using PHP?

mysql_fetch_array: - Fetch a result row as an associative array, a numeric array, or both.
 mysql_fetch_assoc:- Fetch a result row as an associative array.
 mysql_fetch_object:- Fetch a result row as an object.
 mysql_fetch_row:- Get a result row as an enumerated array.
 27. What are encryption functions in PHP?
 CRYPT(), MD5()

28. What is the functionality of the function htmlentities?

htmlentities():- Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

29. How can we increase the execution time of a php script?

By the use of void set_time_limit(int seconds) Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed. When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

30. How to set cookies?

setcookie('variable','value','time');
 variable - name of the cookie variable
 value - value of the cookie variable
 time - expiry time
 Example:

 Test - cookie variable name
 $i - value of the variable 'Test'
 time()+3600 - denotes that the cookie will expire after an one hour

31. How to store the uploaded file to the final location?

move_uploaded_file( string filename, string destination)

32. What type of headers have to be added in the mail function to attach a file?

33. How can we find the number of rows in a result set using php?

34. How can we know the number of days between two given dates using php?

35. How to open a file?

36. How many open modes available when a file open in PHP?

r , r+ , w , w+ , a , a+ , x , x+

37. Explain the types of string comparision function in PHP.

Function Descriptions
 1. strcmp() Compares two strings (case sensitive)
 2. strcasecmp() Compares two strings (not case sensitive)
 3. strnatcmp(str1, str2); Compares two strings in ASCII order, but any numbers are compared numerically
 4. strnatcasecmp(str1, str2); Compares two strings in ASCII order, case insensitive, numbers as numbers
 5. strncasecomp() Compares two strings (not case sensitive) and allows you to specify how many characters to compare
 6. strspn() Compares a string against characters represented by a mask
 7. strcspn() Compares a string that contains characters not in the mask

38. Explain soundex() and metaphone().

soundex()
 The soundex() function calculates the soundex key of a string. A soundex key is a four character long alphanumeric string that represent English pronunciation of a word. he soundex() function can be used for spelling applications.
 metaphone()
 The metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if said by an English speaking person. The metaphone() function can be used for spelling applications.


39. Explain the types of functions for Splitting String?

Function Descriptions
 1. split() Splits a string into an array by using a regular expression as the delimiter.
 2. spliti() Splits a string into an array by a regular expression and is case insensitive.
 3. str_split() Converts a string into an array where the size of the elements can be specified
 4. preg_split() Splits up a string by a Perl compatible regular expression and returns an array of substrings
 5. explode() Splits up a string by another string (not a regular expression) and returns an array
 6. implode() Joins array elements together by a string and returns a string

40. Explain Whitespace Characters.

Whitespace Character ASCII Value(Decimal/Hex) Descriptions
 " " 32 (0x20)) An ordinary space
 "\t" 9(0x0) A tab.
 "\n" 10(0x0A) A newline (line feed).
 "\r" 13(0x0D)) A carriage return.
 "\0" 0(0x00)) The NULL-byte.
 "\x0B" 11(0x0B)) A vertical tab.

 

41. What do you mean range()?

Starting from a low value and going to a high value, the range() function creates an array of consecutive integer or character values. It takes up to three arguments: a starting value, an ending value, and an increment value. If only two arguments are given, the increment value defaults to 1.
 Example :


42. Explain Creating and Naming an Array.

Function Descriptions
 1. array() Creates an array
 2. array_combine() Creates an array by using one array for keys and another for its values
 3. array_fill() Fills an array with values
 4. array_pad() Pads an array to the specified length with a value
 5. compact() Creates array containing variables and their values
 6. range() Creates an array containing a range of elements

43. How to read and display a HTML source from the website url?

 $filename="http://www.kaptivate.in/";
 $fh=fopen("$filename", "r");
 while( !feof($fh) ){
 $contents=htmlspecialchars(fgets($fh, 1024));
 print "
<pre>$contents</pre>
";
 }
 fclose($fh);

44. How to display your correct URL of the current web page?

45. Explain $_FILES Superglobal Array.

Array Descriptions
 $_FILES['userfile']['name'] The original name of the file on the client machine.
 $_FILES['userfile']['type'] The MIME type of the file, if the browser provided this information. An example would be "image/gif".
 $_FILES['userfile']['size'] The size, in bytes, of the uploaded file.
 $_FILES['userfile']['tmp_name'] The temporary filename of the file in which the uploaded file was stored on the server.
 $_FILES['userfile']['error'] The error code associated with this file upload.

 

46. Explain mysql_error().

The mysql_error() message will tell us what was wrong with our query, similar to the message we would receive at the MySQL console.

47. What types of MYSQL function available in PHP?

Database Function Descriptions
 1. mysql_connect() Opens a connection to a MySQL server.
 2. mysql_pconnect() Opens a persistent connection.
 3. mysql_selectdb() Selects the default database.
 4. mysql_change_user() Changes the identity of the user logged on.
 5. mysql_list_dbs Lists databases for this MySQL server.
 6. mysql_list_tables Lists tables in the database.

48. How to get no. of rows using MYSQL function?

Database Function Descriptions
 1. mysql_fetch_assoc() Returns one result row, as an associative array.
 2. mysql_fetch_row() Returns one result row, as an array.
 3. mysql_affected_rows() Returns number of rows affected by query.
 4. mysql_num_rows() Returns number of rows selected.
 5. mysql_list_dbs Lists databases for this MySQL server.
 6. mysql_fetch_object() Returns a result row, as an object.

49. Explain mysql_errno().

Returns the numerical value of the error message from previous MySQL operation.

50. What types of MYSQL function available for affecting columns

Array Descriptions
 mysql_fetch_field() Gets column information from a result and returns as an object.
 mysql_field_name() Gets the name of the specified field in a result.
 mysql_list_fields() Sets result pointer to a specified field offset.
 mysql_num_fields() Gets number of fields in a result.
 mysql_field_seek() Sets result pointer to a specified field offset.
 mysql_field_type() Gets the type of the specified field in a result.
 mysql_field_len() Returns the length of the specified field.
 mysql_field_table() Gets name of the table the specified field is in.
 mysql_tablename() Gets table name of field.

 

51. What is Constructors and Destructors?

CONSTRUCTOR : PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.

52. Why do we create an instance of a class?

To create an instance of a class, the new keyword must be used. An object will always be created unless the object has a constructor defined that throws an exception on error. Classes should be defined before instantiation (and in some cases this is a requirement).If a string containing the name of a class is used with new, a new instance of that class will be created. If the class is in a namespace, its fully qualified name must be used when doing this.

53. What is properties of class?

Class member variables are called "properties". We may also see them referred to using other terms such as "attributes" or "fields", but for the purposes of this reference we will use "properties". They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

54. Explain Constant in Class.

It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that we don't use the $ symbol to declare or use them.The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.

55. Explain the visibility of the property or method.

The visibility of a property or method must be defined by prefixing the declaration with the keywords public, protected or private.

Class members declared public can be accessed everywhere.
 Members declared protected can be accessed only within the class itself and by inherited and parent classes.
 Members declared as private may only be accessed by the class that defines the member.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

*