20 basic PHP interview questions you must know and master (with answers)

青灯夜游
Release: 2023-04-10 07:30:02
forward
6636 people have browsed it

This article will share with you 20 basic PHP interview questions to help you consolidate your foundation. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

20 basic PHP interview questions you must know and master (with answers)

Recommended study: "PHP Video Tutorial"

1. What is object-oriented? What are the main features?

Object-oriented is a design method for programs, which helps improve the reusability of programs and makes the program structure clearer.

Main features: encapsulation, inheritance, polymorphism.

2. What is the difference between SESSION and COOKIE? Please explain the reasons and functions of the protocol?

http stateless protocol cannot distinguish whether the user is from From the same website, the same user requesting different pages cannot be regarded as the same user.

SESSION is stored on the server side, and COOKIE is stored on the client side. Session is relatively secure. Cookies can be modified by certain means and are not safe. Session relies on cookies for delivery. After disabling cookies, the session cannot be used normally.

Disadvantages of Session: Saved on the server side, each read is read from the server, which consumes resources on the server. Session is saved in a file or database on the server side. It is saved in a file by default. The file path is specified by session.save_path in the PHP configuration file. Session files are public.

3. What are the meanings of 302, 403, and 500 codes in HTTP status?

One, two, three, four and five principles: (i.e. one: message series; two: success series; three: redirection series; four: request error series; five: server-side error series.)

  • 302: Temporary transfer successful, the requested content has been moved to the new location
  • 403: Access Forbidden
  • 500: Internal server error
  • 401: Represents unauthorized

4. Please write down the meaning of the data type (int char varchar datetime text); what is the difference between varchar and char?

  • Int Integer
  • char Fixed-length character
  • Varchar Variable-length character
  • Datetime Datetime
  • Text text type

The difference between Varchar and char:

char is a fixed-length character type. It takes up as much space as it allocates. Varchar is a variable-length character type. It takes up as much space as the content is, which can effectively save space. Since the varchar type is variable, the server has to perform additional operations when the data length changes, so the efficiency is lower than that of the char type.

5. What are the basic differences between MyISAM and InnoDB? How is the index structure implemented?

The MyISAM type does not support transactions, table locks, and is prone to fragmentation. It needs to be optimized frequently and has fast read and write speeds. It is suitable for applications with frequent queries;

The InnoDB type supports transactions. , row lock, has crash recovery capability, and the read and write speed is slower than MyISAM. It is suitable for applications with a lot of insert and update operations. It takes up a lot of space and does not support full-text indexing.

Create index: alert table tablename add index index name (`field name`)

6. Difference between isset() and empty()

isset determines whether the variable exists. Multiple variables can be passed in. If one of the variables does not exist, it will return false. empty determines whether the variable is empty and false. Only one variable can be passed. If it is empty, it will be false. Return true.

7. Please explain the difference between passing by value and passing by reference in PHP. When to pass by value and when to pass by reference?

Pass by value: Any changes to the value within the function scope will be ignored outside the function

Pass by reference: Any change to the value within the function scope will also be ignored outside the function Reflecting these modifications

Advantages and Disadvantages: When passing by value, PHP must copy the value. Especially for large strings and objects, this can be a costly operation. Passing by reference does not require copying the value, which is very good for improving performance.

8. What is the function of error_reporting in PHP?

Set PHP's error reporting level and return the current level.

9. Tell me about your understanding of caching technology?

Caching technology is to cache dynamic content into files, and access dynamic pages within a certain period of time to directly call the cached files without having to revisit the database.

10. Nowadays, MVC three-layer structure is often used in programming. What are the three layers of MVC? What are the advantages?

The three layers of MVC refer to: business model, view, and controller. The controller layer calls the model to process the data, and then maps the data to the view layer for display.

The advantages are:

① It can realize code reusability and avoid code redundancy;

②M and V can achieve code separation, so that the same program can use different expressions

11. What are the advantages of AJAX?

ajax is an asynchronous transmission technology that can be implemented through javascript or the JQuery framework to achieve partial refresh, which reduces the pressure on the server and improves the user experience.

12. In the development of the program, how to improve the operating efficiency of the program?

  • Optimize SQL statements, try not to use select * in query statements, use which field to check which field;

  • Use less subqueries and use table connections instead;

  • Use less fuzzy queries;

  • Create indexes in the data table;

  • Generate cache for data frequently used in the program.

13. For websites with large traffic, what methods do you use to solve the traffic problem?

  • Use cache effectively , increase cache hit rate
  • Use load balancing
  • Use cdn to store and accelerate static files
  • Ideas to reduce database usage
  • View statistics Where is the bottleneck?
  • Reverse proxy

14. What is the difference between the statements include and require? In order to avoid including the same file multiple times, what statements can be used to replace them?

Difference: When it fails: include generates a warning, while require generates a direct error interrupt. require loads the include before running and loads it at runtime instead: require_onceinclude_once

15. What is the difference between foo() and @foo()?

@ represents all warnings and is ignored

16. Brief description PHP's garbage collection mechanism.

Variables in php are stored in the variable container zval. In addition to storing variable types and values, zval also has is_ref and refcount fields. refcount indicates the number of elements pointing to the variable, and is_ref indicates whether the variable has an alias. If refcount is 0, the variable container is recycled.

If a zval's refcount is greater than 0 after being reduced by 1, it will enter the garbage buffer. When the buffer reaches the maximum value, the recycling algorithm will loop through the zval to determine whether it is garbage and release it.

17. How to maximize the security of PHP?

How to avoid SQL injection vulnerabilities and XSS cross-site scripting vulnerabilities? Answer: Basic principles: Do not show server or program design details to the outside world (block errors), do not trust any user-submitted data (filter user submissions).

18. Differences between echo, print_r, print, and var_dump

  • echo: statement structure;
  • print: is a function with a return value
  • print_r: can print arrays, objects
  • var_dump: can print object arrays, and has data types

19. Write the characteristics of smarty templates

Fast speed, compilation, caching technology, plug-in mechanism, powerful performance logic

20. If you need to output the content input by the user as it is, before entering the data into the database , which function should be used to process?

htmlspecialchars or htmlentities

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of 20 basic PHP interview questions you must know and master (with answers). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
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