Home >Backend Development >PHP Tutorial >PHP interview summary
The content introduced in this article is about the PHP interview summary, which has a certain reference value. Now I share it with you. Friends in need can refer to it
PHP article collects some common basic and advanced interview questions.
Basics
- The difference between Get and POST
- The difference between single quotes and double quotes
- The difference between isset and empty
- echo, print_r The difference between , print and var_dump
- What is MVC?
- What is the difference between passing by value and passing by reference?
- The difference and relationship between Cookie and Session
> 1. Cookie is on the client (browser), and Session is on the server side
> 2. Session is more secure than Cookie
> 3. The data saved by a single cookie cannot exceed 4K
> 4. Session is based on Cookie. If the browser disables Cookie, Session will also be invalid (but it can be achieved in other ways, such as passing Session in the URL) ID)
Advanced Chapter
- Brief description of S.O.L.I.D design principles
\- | - | -
--- | --- | - --
SRP | Single Responsibility Principle | A class has and has only one reason for change
OCP | Opening and Closing Principle | Ability to extend the behavior of a class without changing it
LSP | Liskov Substitution Principle | Derived classes You can replace the base class with
ISP | Interface isolation principle | Use client-specific fine-grained interface
DIP | Dependency inversion principle | Rely on abstraction rather than concrete implementation
-The difference between PHP7 and PHP5 , what specific new features are added?
> 1. Performance increased by two times
> 2. Added combined comparison operator (<=>)
> 3. Added scalar type declaration and return type Statement
> 4. `try...catch` adds multi-condition judgment, and more Error errors can be handled with exceptions
> 5. Added anonymous classes, now supported 2018/3/5 8:45 :53 supports instantiating an anonymous class through new class, which can be used to replace some complete class definitions that are "burn after use"
- Why is the performance of PHP7 improved compared to PHP5?
> 1. The variable storage bytes are reduced, the memory usage is reduced, and the variable operation speed is improved.
> 2. The array structure is improved, and the array elements and hash mapping table are allocated in the same memory. Reduced memory usage and improved CPU cache hit rate
> 3. Improved the function calling mechanism, reduced some instructions and improved execution efficiency by optimizing the parameter transfer process
- Brief description PHP garbage collection mechanism (GC)
> Before PHP 5.3, reference counting was used to manage memory. All PHP variables are stored in a variable container called `zval`. When the variable is referenced , the reference count will be 1, and when the variable reference count becomes 0, PHP will destroy the variable in memory.
>
> However, for circular references in reference counting, the reference count will not be reduced to 0, which will lead to memory leaks.
>
> After version 5.3, these optimizations were made:
>
> 1. The recycling cycle is not entered every time the reference count is reduced, only the root buffer is full. Then start garbage collection;
> 2. Can solve the circular reference problem;
> 3. Can always keep memory leaks below a threshold.
To learn more, you can view the PHP manual, [Garbage Collection Mechanism](http://docs.php.net/manual/zh/features.gc.performance-considerations.php).
- How to solve the PHP memory overflow problem
> 1. Increase the memory allocation of the PHP script
> 2. Destroy the variable reference in time
> 3. Data batch processing
-What is the difference between Redis and Memecached?
> 1. Redis supports richer data storage types, String, Hash, List, Set and Sorted Set. Memcached only supports simple key-value structures.
> 2. Memcached key-value storage has higher memory utilization than Redis which uses hash structure for key-value storage.
> 3. Redis provides the transaction function, which can ensure the atomicity of a series of commands.
> 4. Redis supports data persistence and can keep the data in the memory on the disk.
> ; 5. Redis only uses a single core, while Memcached can use multiple cores, so on average Redis has higher performance than Memcached when storing small data on each core.
- How does Redis achieve persistence?
> 1. RDB persistence, saving the state of Redis in memory to the hard disk, which is equivalent to backing up the database state.
> 2. AOF persistence (Append-Only-File), AOF persistence records the database by saving the write status of Redis server lock execution. Equivalent to the commands received by the backup database, all commands written to AOF are saved in the Redis protocol format.
Web Security Prevention
- What is CSRF? How to prevent it?
> CSRF (Cross-site request forgery) is usually called "Cross-site request forgery". It can be understood this way: the attacker steals the user's identity and deceives the server to complete the attack request.
###Precautions:######1. Use verification code
2. Add token token to each request and verify
- What is XSS? How to prevent it?
> In order to achieve the purpose of maliciously attacking users.
There are many ways to prevent XSS attacks. The core essence is: never trust user input data and always maintain filtering of user data.
- What is SQL injection? How to prevent it?
> SQL injection means that the attacker deceives the server in some ways, and as a result executes some SQL that should not be executed.
Common scenarios of SQL injection
1. A large amount of junk data is injected into the database, causing the server to run slowly and crash.
2. Using SQL injection to expose the private data of the application
Precautionary measures:
1. Maintain filtering of user data
2. Do not use dynamic assembly of SQL
3. Add input verification, such as verification code
4. Encrypt private data and prohibit plain text storage
Extended reading
-[3-year PHPer interview summary]( http://coffeephp.com/articles/4?utm_source=laravel-china.org)
- [Garbage collection mechanism](http://docs.php.net/manual/zh/features.gc.performance- considerations.php)
- [S.O.L.I.D Object-oriented design](https://laravel-china.org/articles/4160/solid-object-oriented-design-and-programming-oodoop-notes?order_by=created_at&)
- [A brief talk about IOC--explain clearly what IOC is](http://www.cnblogs.com/DebugLZQ/archive/2013/06/05/3107957.html)
- [The difference between Redis and Memcached ](https://www.biaodianfu.com/redis-vs-memcached.html)
- [CSRF Attack and Defense](https://www.cnblogs.com/phpstudy2015-6/p/6771239.html )- [XSS cross-site scripting attack](https://www.cnblogs.com/phpstudy2015-6/p/6767032.html#_label9)
2017php classic interview questions
2017 latest PHP classic interview questions summary
Summary of php interview questions
###The above is the detailed content of PHP interview summary. For more information, please follow other related articles on the PHP Chinese website!