Home > Backend Development > PHP Tutorial > Come and have some basic PHP interview questions

Come and have some basic PHP interview questions

藏色散人
Release: 2023-04-10 06:36:01
forward
4601 people have browsed it

This article summarizes some basic PHP interview questions for everyone. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

1. Which function can be used to convert errors into exception handling?

A:set_error_handler

B:error_reporting

C:error2exception

D:catch

Correct answer: *A *

Answer analysis: set_error_handler () can specify a callback function. When an error occurs, it will be automatically handled through the specified callback function. Just throw a new exception in the callback function.

2. Which of the following descriptions of shell functions is correct?

A: The shell function can be called first and then defined

B: The shell function needs to be defined using the keyword function

C: The variables within the shell function can be declared as local variables

D: The shell function can only return a value through return, 1 is success, 0 is failure

Correct answer: C

Answer analysis: shell function must Define first before calling; when declaring, there is no need to use keywords; local variables within the function can be defined through local; shell function return value, 0 is success, non-0 is error, other options are correct

3. The following about The incorrect statement about full-text search technology is:

A: Solr is a new generation of full-text search component. It is much more efficient than Lucene in search, and it also supports HTTP access. It is also very convenient to call Solr from PHP. .

B: In MySQL, you can create a FULLTEXT index for a field to achieve full-text search. Currently, both MyISAM and InnoDB tables support FULLTEXT indexes.

C: Sphinx is a SQL-based full-text search engine that can be combined with MySQL for full-text search. It can provide more professional search functions than the database itself.

D: CJKAnalyzer, the binary word segmentation analyzer that comes with Lucene, is very fast in word segmentation and can meet the needs of general full-text retrieval.

Correct answer: *A *

Answer analysis: Solr is a new generation of full-text retrieval component. It is based on Lucene, so it is nonsense to say that it is faster than Lucene:)

4. Which statement about the singleton pattern is wrong?

A: The purpose of the singleton mode is to ensure that only one instance of a class can exist in the global environment

B: The single-interest mode generally requires that the constructor be set to private

C: You only need to set the constructor to private to ensure that there is only one instance in the world

D: The function of connecting to the database is usually implemented in the singleton mode

Correct answer :*C *

Answer analysis: Setting the constructor to private only ensures that new instances cannot be created through new, but multiple instances can still be created through clone, deserialization, etc.

5. Which of the regular engine expressions is wrong?

A Regular engines can be mainly divided into two categories: one is DFA and the other is NFA.

B Generally speaking, the NFA engine searches faster. But DFA is expression-oriented and easier to manipulate, so programmers generally prefer DFA engines!

C NFA expression dominates, DFA text dominates.

D You can use whether it supports ignoring priority quantifiers and group capture to determine the engine type: supports NFA, does not support DFA

Correct answer: B

Answer analysis: The correct statement should be: Generally speaking, DFA engine searches faster. But NFA is expression-oriented and easier to manipulate, so programmers generally prefer NFA engines!

6. Which of the following options can be matched by the regular expression in the box?

/.Sd/

A. 123

B. **1234

C. 1234

D.123

Correct answer: B

Answer analysis: The key point of this question is to understand the meaning of this regular expression - from left to right, the first is zero or more arbitrary characters ( .), followed by an asterisk (), then 123, and finally a number. So the answer is B.

7. Which of the following statements about databases is wrong?

A: For efficiency, the database can have multiple reading libraries

B: The database can use master-slave for hot standby

C: The database cannot provide multi-master and multi-slave architecture

D: The database master and slave are synchronized through logs

Correct answer: C

Answer analysis: The database can provide a multi-master and multi-slave architecture.

8. Which of the following is not a way to fix XSS vulnerabilities?

A: Perform htmlspecialchas filtering on parameters

B: Use whitelist filtering on parameters

C: Do not allow input content to be displayed in the browser

D: It is forbidden to output the content input by the user in the js tag

Correct answer: *A *

Answer analysis: This type of filtering can solve the angle bracket type XSS, Unable to resolve xss

in js tag 9. Which of the following is not a PHP SAPI mode?

A.ISAPI

B.CGI

C.FastCGI

D.RESTFUL API

Correct answer: D

Answer analysis: A~C are the most commonly used patterns, and D is an interface organization method.

10. To traverse a large file line by line, which of the following methods has higher performance?

A: Write a class that implements the IteratorAggregate interface, and use foreach traversal through this class.

B: Use file_get_contents to load the file contents into memory at once, and then traverse line by line.

C: Through the exec function, call the shell tool to traverse

D: Use a class library written by others

Correct answer: A

Answer analysis: Use IteratorAggregate to open the file and traverse it line by line by moving the pointer , not affected by file size. Using file_get_contents to process large files can easily cause PHP memory overflow; calling exec will create additional processes and affect performance; the quality of class libraries written by others may not be high.

11. Which of the following options is not a principle that design patterns should follow?

A: Composition is better than inheritance

B: Programming for interfaces

C: Reduce coupling as much as possible

D: Try to use high-performance syntax

Correct answer: D

Answer analysis: The focus of the design pattern is the maintainability and reusability of the code. Option D is not the focus of the design pattern.

12. Which of the following expressions about backtracking is wrong?

A ab.lmn matches abcdeflmnghijklmn in abcdeflmnghijklmn

B ab.?lmn matches abcdeflmn in abcdeflmnghijklmn

C ab??c matches abcdeflmnghijklmn

D .*lmn matches abcdeflmn in abcdeflmnghijklmn

Correct answer: D

Answer analysis: D is a greedy match, so the matching result should be abcdeflmnghijklmn

13. If the try catch finally syntax structure is used in the function, where should the return be written?

A: finally in

B: try in

C: catch in

D: Any position

Correct Answer: A

Answer analysis: finally will continue to execute after return in try. If there is also return in finally, the final return value will be the value of return in finally.

14. The following statement about NOSQL is incorrect:

A: Redis supports data structures such as strings, hashes, lists, sets, and ordered sets. Currently, Redis does not support transactions. .

B: MongoDB supports AP in CAP theorem, MySQL supports CA in CAP, all of which support the impossible existence.

C: MongoDB can directly insert data without creating the Collection structure first. Currently, MongoDB does not support transactions.

D: Memcache supports both TCP protocol and UDP protocol. We can store PHP Session in Memcache.

Correct answer: A

Answer analysis: Redis supports transactions.

15. Which statement about Innodb lock mechanism is wrong?

A: Innodb provides two lock mechanisms: table lock and row lock

B: Innodb’s table lock will be triggered when the table changes

C: Innodb When updating, exclusive locks will be automatically added to the rows involved and a mirror copy will be created. At this time, the data of the mirror copy will be queried when selecting.

D: Reading is not affected in Innodb row lock state , writing will be affected (data involved)

Correct answer: A

16. Which of the following is created every Wednesday 01:00~04:00 every 3 Execute crontab command once every minute?

A: 1,4 3 /bin/bash /home/sijiaomao/ok.sh

B:/3 1,4 3 /bin/bash /home/sijiaomao/ok.sh

C:/3 1-4 3 /bin/bash /home/sijiaomao/ok.sh

D:/3 1-4 * /bin/bash /home/sijiaomao/ok .sh

Correct answer: C

Answer analysis: A: Executed every minute at 1:04 o'clock every Wednesday B: Every 3 o'clock at 1:04 o'clock every Wednesday Execute once every minute C: Meet the requirements D: Execute once every 3 minutes at 1:04 every day

17. Before splitting, the data required for many lists and detail pages in the system can be obtained through sql join Completed. After splitting, the database may be distributed on different instances and different hosts, and join will become very troublesome. Which of the following methods is not an effective solution to this problem?

A Global table, some tables that all modules in the system may depend on are saved in each library.

B Fields are redundant. While saving the "Seller Id" in the "Order Table", the seller's "Name" field is also redundant, so that when querying order details, there is no need to query the "Seller User" surface".

C Master-slave replication separates reading and writing of the database.

D Data synchronization, the tbl_a table in database A is regularly associated with the tbl_b in database B, and the specified table can be synchronized between master and slave at regular intervals.

Correct answer: C

Answer analysis: Master-slave replication separates the reading and writing of the database. It can only expand read concurrency, but cannot alleviate the problem of cross-database join.

18. Regarding the network IO model, which of the following is correct?

A.Select is faster than Epoll

B.nginx uses the select model

C.apache supports switching between select and epoll

D.epoll can support greater concurrency

Correct answer: D

Answer analysis: A epoll is faster. B nginx uses the epoll model. C apache only supports select

19. When PHP is executed, there is the following execution process: Scanning (Lexing) - Compilation - Execution - Parsing, whose meanings are:

A: Convert PHP code For language fragments (Tokens), convert Tokens into simple and meaningful expressions, compile the expressions into Opocdes, and execute Opcodes

B in sequence: Convert PHP code into language fragments (Tokens), Convert Tokens into simple and meaningful expressions, execute Opcodes sequentially, and compile expressions into Opocdes

C: Convert PHP code into language fragments (Tokens), compile expressions into Opocdes, execute Opcodes sequentially, and convert Tokens into simple and meaningful expressions

D: Convert PHP code Convert into language fragments (Tokens), compile expressions into Opocdes, convert Tokens into simple and meaningful expressions, and execute Opcodes in sequence

Correct answer: C

Answer analysis: The correct answer is C, and the correct order is: Scanning (Lexing), Parsing, Compilation, Execution

The above is the detailed content of Come and have some basic PHP interview questions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template