Home >Backend Development >PHP Problem >Some classic interview questions in 2018

Some classic interview questions in 2018

王林
王林Original
2019-08-19 13:50:365346browse

Today I have collected some interview questions for you. I hope it will be helpful to you. Thank you!

Recommended PHP related video tutorials: https://www.php.cn/course/list/29/type/2.html

1. One of the major advantages of the PHP language is that it is cross-platform. What is cross-platform?

The optimal running environment of PHP is Apache MySQL PHP. This running environment can be used in different operating systems (such as windows, Linux, etc.) ) and is not restricted by the operating system, so it is called cross-platform

2. How many methods are there for data submission in WEB development? What are the differences? Which method does Baidu use?

Two methods of Get and post

Differences:

1. Get obtains data from the server, and post transmits data to the server

2. Get passes the value in Visible in the url, post is not visible in the url

3. The value passed by Get is generally within 2KB, and the size of the value passed by post can be set in php.ini

4. The security of get is not Low, post security is higher, but the execution efficiency is higher than Post

Recommendations:

1. The get type is less secure than the Post type and contains confidential information. It is recommended to use the Post data submission type;

2. It is recommended to use the Get method for data query; it is recommended to use the Post method for adding, modifying or deleting data;

The get method used by Baidu can be seen from its URL

3. Understand which frameworks, template engines, systems, etc. of PHP

Frameworks: There are many frameworks, such as zendframe, CI, Yii, etc. The one we have learned is thinkphp

Template engine: There are many, including them in textbooks. What we have learned is smarty

System: there are many, for example: Kangsheng’s products (uchome, supesite, discuzX, etc.), Empire System, DEDE(Dreamweaver), ecshop, etc.

4. Tell me about your What web front-end technologies have you mastered?

Proficient in DIV CSS web page layout, JavaScript, jQuery framework, photoshop image processing

5. 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

6. Security is crucial to a program. Please tell me what security mechanisms should be paid attention to during development?

① Prevent remote submission; ② Prevent SQL injection and filter special codes; ③Prevent the registration machine from flooding and use verification codes;

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

①Optimize SQL statements and query statements Try not to use select *, and use which field to check which field; use less subqueries and can be replaced by table connections; use less fuzzy queries; ② Create indexes in the data table; ③ Generate cache for data frequently used in the program;

8. Can PHP be used with other databases?

PHP is the best combination with MYSQL database. Of course, PHP can also be used with other databases, such as MSSQL, etc. PHP has reserved functions for operating MSSQL, which can be used as long as it is turned on.

9. Nowadays, MVC three-layer structure is often used in programming. Which three layers does MVC refer to and what are its 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: ① Code reusability can be achieved , to avoid code redundancy; ②M and V implement code separation, so that the same program can use different expressions

10. Understanding of json data format?

JSON(JavaScript Object Notation) is a lightweight data exchange format. The json data format is fixed and can be used for data transmission in multiple languages

The function that processes json format in PHP is json_decode( string $json [, bool $assoc ] ), which accepts a JSON format string and Convert it into a PHP variable, and the parameter json is a string in the json string format to be decoded. assocWhen this parameter is TRUE, array will be returned instead of object;

Json_encode: Convert PHP variables into json format

11. What are the differences between Print, echo, and print_r?

① Both echo and print can do output, different Yes, echo is not a function and has no return value, while print is a function with a return value, so relatively speaking it will be faster to just output echo, and print_r is usually used to print information about variables, usually used in debugging.

② print is to print a string

③ print_r is to print composite types such as array objects

12. What is the difference between SESSION and COOKIE?

①Storage location: session is stored on the server, cookie is stored in the browser

②Security: session security is higher than cookie

③session is a 'session service', when used The service needs to be turned on. Cookies do not need to be turned on. You can use it directly

13. What are the common functions for processing arrays in PHP? (Focus on the 'parameters' and 'return value' of the function)

①array() creates an array; ②count() returns the number of elements in the array; ③array_push() inserts one or more elements into the end of the array (push); ④array_column() returns the value of a single column in the input array ;⑤array_combine() creates a new array by merging two arrays;⑥array_reverse() returns the array in reverse order;⑦array_unique() removes duplicate values ​​in the array;⑧in_array() checks whether the specified value exists in the array;

14. Commonly used functions in PHP to process strings? (Focus on the 'parameters' and 'return values' of the function)

①trim() removes the blanks on both sides of the string characters and other characters;

②substr_replace() replaces part of the string with another string;

③substr_count() counts the number of times a substring appears in the string;

④substr() returns a part of the string;

⑤strtolower() converts the string to lowercase letters;

⑥strtoupper() converts the string to uppercase letters;

⑦strtr() Convert specific characters in a string;

⑧strrchr() Find the last occurrence of a string in another string;

⑨strstr() Find the last occurrence of a string in another character The first occurrence in the string (case-sensitive); strrev() reverses the string; strlen() returns the length of the string; str_replace() replaces some characters in the string (case-sensitive); print( ) Output one or more strings; explode() breaks the string into an array; is_string() detects whether the variable is a string; strip_tags() removes HTML tags from a string; mb_substr() is used to cut Chinese and English functions

15. Commonly used functions in PHP to process time? (Focus on the 'parameters' and 'return values' of the function)

 date_default_timezone_get() Return to the default time zone.

 date_default_timezone_set()Set the default time zone.

 date()Format local time/date.

 getdate()Return date/time information.

 gettimeofday()Returns the current time information.

 microtime()Returns the number of microseconds in the current time.

 mktime()Returns the Unix timestamp of a date.

 strtotime()Parses any English text date or time description into a Unix timestamp.

 time()Returns the Unix timestamp of the current time.

16. What are the commonly used functions for PHP to process databases? (Focus on the 'parameters' and 'return values' of the function)

Please refer to the PHP manual and read it carefully. This item is very important

 17. Commonly used functions for operating files in PHP? (Focus on the 'parameters' and 'return values' of the function)

 ①Open the file;②Delete File; ③ Read file; ④ Write file; ⑤ Modify file; ⑥ Close file; ⑦ Create file, etc. This item is very important. It is often used to generate cache or static files at work. Please refer to the PHP manual and read it carefully.

 18. Commonly used functions of PHP to operate directories (folders)? (Focus on the 'parameters' and 'return values' of the function)

 ①Open the directory;② Delete the directory; ③ Read the directory; ④ Create the directory; ⑤ Modify the directory; ⑥ Close the directory, etc. This item is very important. It is often used to create or delete directories for uploaded files at work, and create or delete directories for cached and static pages. , please refer to the PHP manual and check carefully

19. What is MVC? What is the relationship between them?

Answer: MVC is a development model, which is mainly divided into Three parts: m (model), which is the model, is responsible for the operation of data; v (view), which is the view, is responsible for the display of front and backends; c (controller), which is the controller, is responsible for business logic

20. What is oop?

Answer: oop is object-oriented programming. Object-oriented programming is a computer programming architecture. A basic principle of OOP is that a computer program is composed of a single It is composed of units or objects that are used by subroutines

21. OOP has three major characteristics

1. Encapsulation: also called information hiding, it is to hide an The use and implementation of the class are separated, and only some interfaces and methods are kept in contact with the outside, or only some methods are exposed for developers to use. Therefore, developers only need to pay attention to how this class is used, rather than its specific implementation process. This can achieve MVC division of labor and cooperation, effectively avoid interdependence between programs, and achieve loose coupling between code modules.

2. Inheritance: subclasses automatically inherit the properties and methods of their parent class, and can add new properties and methods or rewrite some properties and methods. Inheritance increases code reusability. PHP only supports single inheritance, which means that a subclass can only have one parent class.

3. Polymorphism: The subclass inherits the properties and methods from the parent class and rewrites some of the methods. Therefore, although multiple subclasses have the same method, objects instantiated by these subclasses can obtain completely different results after calling these same methods. This technology is polymorphism. Polymorphism increases software flexibility.

22. What is smarty and what is its function?

Answer: Answer 1: smarty is a template engine written in PHP, and it is also the most famous PHP in the industry. One of the template engines

It separates the logic code and the external display, and provides an easy-to-manage and use method to separate the mixed PHP logic code from the HTML code

Answer 2: Smarty is PHP One of the most famous engine frameworks in the world, our company uses the TP framework, which has encapsulated the smarty template, so it has not been used alone.

Answer 3: Smarty is a template engine, and the most significant thing is that it has Templates can be cached. Generally speaking, templates are made to make a static page, and then cut some dynamic parts inside with any delimiters, then open the template file in PHP, replace the values ​​​​in the delimiters, and then output it, you You can look at the template part in PHPLib.

23. What are the advantages of the TP framework?

Answer: The TP framework is a framework developed by the Chinese ourselves. All kinds of information are relatively complete and can be used domestically. There are many, relatively simple and convenient, and they are free and open source

24. What are the characteristics of TP?

Answer:

1. Multi-table query is very convenient. You can complete the association operation of multiple tables with just a few lines of code in the model

2. Integrate smart templates to separate the front and backend

3. Support multiple caches Technology, especially memcache technical support is very good

4. Naming specifications, models, views, and controllers strictly follow naming rules, and correspond one to one through naming

5. Support multiple url modes

6. Built-in ajax return method, including xml, json, html, etc.

7. Support application extension, class library extension, driver extension, etc.

24, TP Big letter functions in the framework?

Answer: U: Assembly of url

A: Internal instantiation controller

S: Cache processing

R: Call the operation method of a controller

D: Instantiate a custom model class

M: Instantiate a basic model class

I: Get parameters

L: Set or get the current language

C: Set or get, save the configuration

25. Please introduce the laravel framework?

Answer: The design ideas of the laravel framework are relatively advanced and are very suitable for applying various development models. As a framework, it has prepared everything for you. Composer is the future of PHP. Without composer, PHP will definitely decline

The biggest feature and excellence of laravel framework is that it integrates the relatively new features of PHP, as well as various design patterns, Ioc patterns, dependency injection, etc.

26. What does laravel have? Features?

Answer: Answer 1:

1. Powerful rest router: it can be called with a simple callback function and quickly binds the controller and router

2.artisan: command line tool, many manual tasks are automated

3.Inheritable templates, simplifying the development and management of views

4.blade template: rendering faster

5.ORM operation database

6.migration: management database and version control

7. The testing function is also very powerful

8.composer is also a highlight

Answer 2: The laravel framework introduces facade, dependency injection, Ioc mode, and various design patterns, etc.

27. Please briefly describe the optimization of the database?

Answer: Database optimization can be optimized from four aspects:

1. Structural layer: The web server uses a load balancing server, the mysql server uses master-slave replication, and read-write separation

2. From the storage layer: Use an appropriate storage engine and use three paradigms

3. From the design layer: Use partitions to separate tables, indexes, and use appropriate field attributes for table fields. Appropriately use reverse paradigm and enable mysql cache

4. SQL statement layer: When the results are the same, use SQL statements that are efficient, fast and save resources

28. How to solve exception handling?

Answer: Throw exception: use try...catch, the exception code is placed in the try code block. If the exception is not triggered, the code continues to execute. If the exception is triggered, An exception will be thrown. The Catch code block catches the exception and creates an object containing the exception information. $e->getMessage(), outputs abnormal error message.

The current implementation of shopping carts is mainly through cookies, sessions or combined with databases. Let’s analyze their mechanisms and functions.

1.Cookie

2.Cookie is a piece of information generated by the server and stored on the client. It defines a mechanism for a Web server to store and return information on the client. The cookie file contains domain, path, lifetime, and variable values ​​set by the server. When the user visits the same Web server in the future, the browser will send the cookie to the server unchanged. By allowing the server to read the information originally saved to the client, the website can provide visitors with a series of conveniences, such as identifying the user's identity during online transactions, preventing users from repeatedly entering their name and password in situations where security requirements are not high, and the home page of the portal website. Customize, target ads and more. Using the characteristics of cookies, the functions of WEB applications are greatly expanded. Not only can the connection between the server and the client be established, because the cookie can be customized by the server, the cookie value generated by the shopping information can also be stored on the client, thereby realizing the shopping cart. Function. Using a cookie-based method to implement a session or shopping cart between the server and the browser has the following characteristics:

3. Cookies are stored on the client side and occupy very few resources. The browser allows 300 cookies to be stored. , the size of each cookie is 4KB, which is enough to meet the requirements of the shopping cart and also reduces the load on the server;

4. Cookies are built into the browser and are easy to use. Even if the user accidentally closes the browser window, the information in the shopping cart will not be lost as long as it is within the validity period defined by the cookie;

5. Cookies are not executable files, so they will not be executed in any way. Therefore, it will not bring viruses or attack the user's system;

6. The cookie-based shopping cart requires that the user's browser must support and be set to enable cookies, otherwise the shopping cart will be invalid;

7. There is a debate about cookies infringing on visitors' privacy, so some users will disable the cookie function of the machine.

2. Session

1. Session is another way to implement a shopping cart. Session provides the function of saving and tracking the user's status information, so that the variables and objects defined by the current user in the session can be shared between pages, but cannot be accessed by other users in the application. The most important difference between it and cookies is that , session stores the user's private information during the session on the server side, improving security. After the server generates a session, the client will generate a sessionid identification number and save it on the client to maintain synchronization with the server. This sessionid is read-only. If the client disables the cookie function, the session will be transmitted between pages by appending parameters to the URL, or implicitly submitting it in a form, etc. Therefore, it is safer and more effective to use sessions to manage users.

2. Similarly, the shopping cart can also be implemented using session. The characteristics of this method are:

1. Session uses a new mechanism to maintain synchronization with the client and does not depend on client settings. ;

2. Compared with cookies, session is information stored on the server side, so it is more secure. Therefore, identity marking, shopping and other information can be stored in the session;

3. Sessions will occupy server resources and increase the load on the server. Especially when there are many concurrent users, a large number of sessions will be generated, affecting the performance of the server;

4. Because the information stored in sessions is more sensitive and is based on files The form is saved on the server, so there are still security risks.

The above are collected interview questions, I hope it will be helpful to everyone. Thanks!

For more related questions, please visit the PHP Chinese website: https://www.php.cn/

The above is the detailed content of Some classic interview questions in 2018. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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