Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common PHP interview questions?

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "what are the common PHP interview questions", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what are the common PHP interview questions" can help you solve your doubts? let's follow the editor's ideas to learn new knowledge.

100 common PHP interview questions

1) what is PHP?

PHP is a script-based web language that allows developers to create web pages dynamically.

2) the full name of PHP?

Hypertext Preprocessor (hypertext preprocessor).

3) which programming languages are similar to PHP?

The PHP syntax is similar to Perl and C.

5) which version of PHP is actually used?

Version 7 is recommended.

6) how do I execute PHP scripts from the command line?

In the command line interface (CLI), specify the file name of the script to execute, as follows:

Php script.php

7) how to run interactive PHP Shell from the command line interface?

Use the PHP CLI program with the-an option, as follows:

Php-a

8) what are the two most common ways to start and end blocks of PHP code correctly?

The two most common ways to start and end PHP scripts are:

And

9) how to display the output directly to the browser?

To display the output directly to the browser, we must use special tags.

11) does PHP support multiple inheritance?

PHP only supports single inheritance. PHP's class inherits another class using the keyword extends

12) what do final-decorated classes and methods mean?

Final was introduced in the PHP5 version, and its decorated classes are not allowed to be inherited, and its decorated methods are not allowed to be overridden.

13) how do I compare two objects in PHP?

In PHP, we can use the operator = = to compare whether two objects are instances of the same class and have the same properties and property values.

You can also use the operator = = to compare whether two objects refer to the same instance of the same class.

14) how do PHP and HTML interact?

You can generate HTML through PHP scripts, and you can pass information from HTML to PHP.

15) what type of operation is required to pass values through a form or URL?

To pass values through a form or URL, you need to encode and decode them using htmlspecialchars () and urlencode ().

16) how do PHP and Javascript interact?

PHP and Javascript cannot interact directly because PHP is a server-side language and Javascript is a browser language. However, we can exchange variables because PHP can generate Javascript code to be executed by the browser, and specific variables can be passed back to PHP through URL.

17) what extensions do PHP need to add when dealing with images?

The GD library is required to perform the image processing function.

18) the function of the function imagetypes ()?

Imagetypes () gives the image formats and types supported by the current version of GD-PHP.

19) what is the function to get the image properties (size, width, and height)?

Get the picture size size:getimagesize (); get the picture width width:imagesx (); get the picture height height:imagesy ().

20) what is the difference between include () and require () when execution fails?

Include () will generate a warning that does not affect the execution of subsequent programs. Require () will generate a fatal error and the subsequent program will stop execution.

21) what is the main difference between require () and require_once ()?

Require () and require_once () perform the same task, except that the second function checks to see if the PHP script is included before execution.

(same as include_once () and include ())

22) how do I use PHP scripts to display text?

You can use the following two methods:

23) how to use PHP to display variable information and make it human readable?

To show human-readable results, we used print_r ().

24) how do I set unlimited execution time for PHP scripts?

Add set_time_limit (0) to unlimited execution time at the beginning of the script to prevent PHP errors from "exceeding the maximum execution time". You can also specify it in the php.ini file.

25) what does the PHP error 'Parse error in PHP-unexpected T_variable at line x' mean?

This is a PHP syntax error that indicates that an error on line x stops parsing and executing the program.

26) how do I export data to an Excel file?

The most common and common method is to convert the data to a format supported by Excel. For example, you can write a .csv file, for example, select a comma as the separator between fields, and then use Excel to open the file.

27) what is the function of the file_get_contents () function?

File_get_contents () reads the file and stores it in a string variable.

28) how do I use PHP scripts to connect to MySQL databases?

In order to connect to the MySQL database, you must use the mysql_connect () function:

29) what is the purpose of the mysql_pconnect () function?

The mysql_pconnect () function ensures a persistent connection to the database, which means that the connection is not closed at the end of the PHP script.

This function is no longer supported in PHP7.0 and above.

30) how to deal with the result set of MySQL in PHP?

You can use mysqli_fetch_array, mysqli_fetch_assoc, mysqli_fetch_object or mysqli_fetch_row functions to handle.

31) how do I know the number of rows returned by the result set?

The mysqli_num_rows () function returns the number of rows in the result set.

32) which function provides us with the number of entries affected by the query?

Mysqli_affected_rows () returns the number of entries affected by the SQL query.

33) the difference between the mysqli_fetch_object () and mysqli_fetch_array () functions is?

The mysqli_fetch_object () function collects the first single matching record, while mysqli_fetch_array () collects all matching records from the table.

34) how do I use the GET method to access data sent over URL?

To access the data sent through the GET method, we use the $_ GET array, as follows:

Www.url.com?var=value$variable = $_ GET ["var"]; will now contain 'value'

35) how do I use the POST method to access data sent over URL?

To access data sent in this way, use the $_ POST array.

Imagine that when a user clicks the submit to post form, there is a form field called "var" on the form, and then you can access the value like this:

$_ POST ["var"]

36) how do I check that the value of a given variable is a number?

You can use the special function is_numeric () to check whether it is a number.

37) how do I check that the values of a given variable are alphanumeric characters?

You can use the special function ctype_alnum to check whether it is an alphanumeric character.

38) how do I check whether a given variable is empty?

If we want to check whether the variable has a value, we can use the empty () function.

39) what is the function of the unlink () function?

The unlink () function is dedicated to file system processing. It is used to delete files.

40) what is the function of the unset () function?

The unset () function is dedicated to variable management. It makes the variable undefined.

41) how do I escape data before storing it in a database?

The addslashes function enables us to escape data before storing it in the database.

42) how do I remove escaped characters from a string?

Using the stripslash function, we can remove escaped characters from a string.

43) how do we automatically escape incoming data?

We must enable the magic quotation mark entry in the configuration file of PHP.

44) what is the function of the get_magic_quotes_gpc () function?

The function get_magic_quotes_gpc () tells us whether the magic quotation marks are turned on.

45) can I delete HTML tags from the data?

The strip_tags () function enables us to clear the string from the HTML tag.

46) what is the use of static variables in a function?

Static variables are only defined for the first time in the function, and their values can be modified as follows during the function call:

47) how do I define accessible variables in PHP script functions? ?

Use the global keyword.

48) how do I return a value from a function?

Use the directive 'return $value;'.

49) what is the most convenient hash method for hash passwords?

It is better to use crypt (), which supports several hash algorithms itself, or hash (), which supports more variants than crypt (), rather than common hash algorithms, such as MD5, SHA1, or sha256, because they are considered to have security problems. Therefore, hash passwords that use these algorithms may create vulnerabilities.

50) which encryption extension can generate and verify digital signatures?

The PHP-OpenSSL extension provides several encryption operations, including digital signature generation and verification.

51) how do I define constants in PHP scripts?

The define () directive allows us to define constants as follows:

Define ("ACONSTANT", 123)

52) how to pass variables by reference?

To be able to pass variables by reference, we use the & symbol in front of the variable, as shown below $var1=&$var2

53) is the comparison between the integer 12 and the string "13" valid in PHP?

"13" and 12 can be compared in PHP because it casts everything to an integer type.

54) how do I cast types in PHP?

The name of the output type must be specified in parentheses before the variable to be cast, as follows:

(int), (integer)-cast to integer

(bool), (boolean)-cast to Boolean

(float), (double), (real)-cast to floating point

(string)-cast to string

(array)-cast to an array

(object)-cast to object

55) when does a conditional statement end with endif?

When the initial if is followed by: then a block of code without curly braces.

56) how to use the ternary conditional operator in PHP?

It consists of three expressions: a condition and two operands that describe the instructions that should be executed when the specified condition is true or false, as follows:

Expression_1?Expression_2: Expression_3

57) what is the function func_num_args () for?

The function func_num_args () is used to provide the number of arguments passed to the function

58) if the variable $var1 is set to 10 and $var2 is set to the character var1, what is the value of $$var2?

$$var2 contains a value of 10.

59) what does it mean to access a class through::

Used to access static methods that do not require object initialization

60) in PHP, are objects passed by value or by reference?

Object is passed by value.

* * 61) is the Parent constructor implicitly called in the class constructor? **

No, the parent constructor must be called explicitly, as follows:

Parent::constructor ($value)

* * 62) what's the difference between _ sleep and _ wakeup? **

_ _ sleep returns an array of all the variables that need to be saved, and _ _ wakeup retrieves them.

* * 63) is it faster? **

1-combines the following two variables:

$variable1 = 'Hello'; $variable2 = 'World'; $variable3 = $variable1.$ variable2

Or

2-$variable3 = "$variable1 $variable2"

$variable3 will contain "Hello World". The first code is faster than the second code, especially for large datasets.

* * 64) what is the definition of a session? **

A session is a logical object that enables us to retain temporary data across multiple PHP pages.

* * 65) how do I start a session in PHP? **

Use the session_start () function to activate the session.

* * 66) how to propagate session ID? **

You can propagate the session ID through the Cookie or URL parameter.

* * 67) what is the meaning of permanent Cookie? **

The permanent cookie is permanently stored in the cookie file on the browser computer. By default, cookies is temporary, and if we close the browser, cookies will be deleted.

* * 68) when will the meeting end? **

The session ends automatically when the PHP script finishes execution, but can be terminated manually using session_write_close ().

* * 69) what is the difference between session_unregister () and session_unset ()? **

The session_unregister () function logs out global variables from the current session, while the session_unset () function releases all session variables.

* * 70) what does $GLOBALS mean? **

GLOBALS is an associative array that includes references to all variables currently defined in the global scope of the script.

71) what does $_ SERVER mean?

$_ SERVER is an array of Web server creation information, including the path, header, script location, and so on.

72) what does $_ FILES mean?

$_ FILES is an array of items that are uploaded to the current script through HTTP POST.

73) what's the difference between $_ FILES ['userfile'] [' name'] and $_ FILES ['userfile'] [' tmp_name']

$_ FILES ['userfile'] [' name'] indicates the original name of the client file

$_ FILES ['userfile'] [' tmp_name'] represents the temporary file name of the file stored on the server.

* 74) how to get the error message when there is a problem with uploading a file *

$_ FILES ['userfile'] [' error'] includes error codes related to uploading files.

75) how do I change the maximum size of the file to upload?

You can change the maximum size of the file to upload by changing the upload_max_filesize in php.ini.

76) what does $_ ENV mean?

An array of variables passed to the current script in an environmental manner.

77) what does $_ COOKIE mean?

An array of variables passed to the current script through HTTP Cookies.

78) what does the scope of a variable mean?

The scope of the variable defines the context of the variable. In most cases, PHP variables have only one variable field. This scope also covers include and require files.

79) what is the difference between the 'BITWISE AND' operator' and the 'LOGICAL AND' operator?

$an and $b-true only if both $an and $b are true

$a & $b-set the bit 1 in both $an and $b to 1

80) what are the two main string operators?

. Operator returns the stitching result of the strings on the left and right sides. The. = operator appends the result on the right to the parameter on the left.

81) what does the array operator'= 'mean?

TRUE if $an and $b have key / value pairs of the same order and type.

82) what's the difference between $a! = $b and $a! = $b?

! = is not equal (TRUE if $an is not equal to $b);! = = is incongruent (TRUE if $an is not exactly equal to $b).

83) how do I determine whether the PHP variable is an instantiated object of a class?

We can use instanceof to verify whether the PHP variable is an instance object of a class.

84) what is the use of the goto statement?

The goto statement can be placed in the PHP program to enable the jump. The target is pointed to by a label followed by a colon, and the instruction is specified as a goto statement, followed by the desired target label.

85) what's the difference between Exception::getMessage and Exception:: getLine?

Exception::getMessage lets us get the exception message, and Exception::getLine lets us get the line where the exception occurred.

86) what does the expression Exception::__toString mean?

Exception::__toString gives a string representation of the exception.

87) how to parse the configuration file?

The function parse_ini_file () enables us to load the ini file specified in the file name and return the settings in it as an associative array.

88) how do we determine if the variable has been set?

The Boolean function isset determines whether the variable is set and that the variable is not NULL.

89) what's the difference between the function strstr () and stristr ()?

The string function strstr (all strings, the string to find) returns a partial string of fields from the first occurrence to the end of the entire string. This function is case sensitive. Stristr () is exactly the same as strstr () except that it is case-insensitive.

90) what's the difference between for and foreach?

For represents as follows:

For (expr1; expr2; expr3)

Expr1 is executed once at the beginning. In each iteration, the expr2 is evaluated. If the evaluation result is TRUE, the loop continues and executes the statement in for. If the evaluation result is FALSE, the loop ends. Expr3 is tested at the end of each iteration.

However, foreach provides an easy way to traverse arrays and is used only with arrays and objects.

91) can I submit a form with a special button?

You can use the document.form.submit () function to submit a form. For example:

92) what's the difference between ereg_replace () and eregi_replace ()?

The function eregi_replace () is the same as ereg_replace (), except that case differences are ignored when matching alphabetic characters.

93) can you protect the special characters in the query string?

Yes, we use the urlencode () function to protect special characters.

94) what are the three types of errors that can occur in PHP?

The three basic error categories are notification (non-critical error), warning (critical error), and fatal error (critical error).

95) what's the difference between .34 and .34?

.34 is octal 34, .34 is hexadecimal 34.

96) how do we pass variables through navigation between pages?

You can use sessions, cookie, or hidden form fields to pass variables between PHP pages.

97) whether you can extend the execution time of PHP scripts

Using set_time_limit (int seconds) can increase the execution time of PHP scripts. The default limit is 30 seconds.

98) can Cookie be destroyed?

Yes, you can do this by setting the expiration time of the cookie.

99) what is the default session time in PHP?

The default session time in php is until the browser is closed.

100) can I use COM components in PHP?

Yes, you can integrate (distributed) component object model components ((D) COM) into the PHP scripts provided in the framework.

Explain whether it is possible to share a single PHP instance among multiple memcache projects?

Yes, you can share an instance of Memcache among multiple projects. Memcache is a memory storage space, and you can run memcache on one or more servers. You can also configure the client to talk to a specific set of instances. Therefore, you can run two different Memcache processes on the same host, but they are completely independent. Unless you have partitioned the data, it is necessary to know which instance to get the data from or which instance to put the data into.

Explain how to update Memcached when you make changes to PHP?

When PHP changes, you can update Memcached in the following ways

Actively clear the cache: clear the cache when inserting or updating

Reset cache: similar to the first method, but not just to delete the key and wait for the next request for data to refresh the cache, but to reset the value after insertion or update.

After reading this, the article "what are the common PHP interview questions" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report