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.
Recommended study: "PHP Video Tutorial"
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.
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.
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.)
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.
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`)
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.
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.
Set PHP's error reporting level and return the current level.
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.
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
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.
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.
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
@ represents all warnings and is ignored
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.
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).
Fast speed, compilation, caching technology, plug-in mechanism, powerful performance logic
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!