This article mainly introduces the latest summary of PHP classic interview questions in 2017 (Part 1). It is very good and has reference value. Friends in need can refer to it
##1. The difference between double quotes and single quotes
- Double quotes interpret variables, single quotes do not interpret variables
- In double quotes Insert single quotes. If there is a variable in the single quotes, the variable explanation
- The double quotes
variable name must be followed by a non-number, letter, or underscore. Special characters, or use {} to enclose the variable, otherwise the part after the variable name will be treated as a whole, causing grammar errors
- Double quotes interpret escape characters, single quotes do not interpret escape characters, but interpreting '\ and \\
- can make single quote characters use single quotes as much as possible. Single quotes are more efficient than Double quotation marks should be taller (because double quotation marks must be traversed first to determine whether there are variables inside, and then operated, while single quotation marks do not need to be judged)
2. Commonly used superglobal variables(8)
- ##$_GET ----->get transmission method
- $POST ----->post transmission method
- $REQUEST ----->Can receive both get and post The value of the method
- ***
- $GLOBALS ----->All variables are placed inside
- $FILE ----->Upload files using
- $SERVER ----->System environment variables
- $SESSION ----->Will be used during session control
- $ COOKIE ----->It will be used for session control
3. The difference between POST, GET, PUT and DELETE methods in HTTP HTTP defines different methods of interacting with the server. The most basic ones are POST, GET, PUT, and DELETE. The full name of the indispensable URL is resource descriptor. We can understand it like this: URL describes a resource on the Internet, and post, get, put, and delegate are operations to add, delete, modify, and check this resource!
3.1 The difference between get and post submission methods in the form
- get adds the parameter data queue to the submission form In the URL pointed to by the action attribute, the value corresponds one-to-one with each field in the form, which can be seen from the URL; post uses the HTTPPOST mechanism to prevent each field in the form and its content from being transmitted to the action attribute in the HTML head. Referring to the url address, the user cannot see this process
- For the get method, the server side uses Request.QueryString to obtain the value of the variable. For the post method, the server side uses Request.Form to obtain it. Submitted data
- get transfers a smaller amount of data, while post transfers a larger amount of data. It is generally unrestricted by default, but in theory, the maximum amount in IIS4 is 80kb. In IIS5 it is 1000k,
- get security is very low, post security is high
- The GET request will send a request for data to the database to obtain information. This request is just like the select operation of the database. It is only used to
- query
the data and will not be modified or added. The data will not affect the content of the resource, that is, the request will have no side effects. No matter how many times you perform the operation, the result is the same.
Different from GET, the PUT request sends data to the server to change the information. This request is just like the update operation of the database, used to modify the content of the data, but The types of data will not be increased, which means that no matter how many PUT operations are performed, the results will not be different. - POST request
is similar to PUT request, both send data to the server, but this request will change the type of data and other resources, just like the insert of the database The operation is the same, new content will be created. Almost all current submission operations are requested using POST.
DELETE request, as the name suggests, is used to delete a certain resource. This request is like the - delete operation
4. Introduction to PHPHypertext Preprocessor----Hypertext Preprocessor
Personal Home Page Original name
Target purpose: Allow web developers to quickly write dynamically generated web pages. Compared with other pages, PHP embeds the program into the
HTML documentfor execution. , much more efficient than CGI that completely generates HTML editingHTML: Hypertext Markup Language
Founder: Rasmus Lerdorf, born in 1968, University of Waterloo, Canada
Ledolf initially wrote the maintenance program in prel language in order to maintain his personal web page, and then rewritten it in c, which eventually led to php/fi
Timeline:
1995.06.08 PHP/FI will be released to the public
-
1995 php2.0, adding support for MySQL
1997 php3.0
2000 php4.0
2008 php5.0
Since php6.0 does not completely solve Unicode encoding, there are basically no applications on the production line. It is basically just a concept product. Many functions have been implemented on php5.3.3 and php5.3.4
Common IDE(Intergrated Development Environment): Integrated Development Environment
Coda (mac)
PHPStrom
Adobe Dreamweaver
NetBeans
Common textEditor, with code highlighting:
NodePad++
SublimeText
PHP Advantages
PHP features:
php uniquely mixes C, Java, Prel and PHP’s own syntax
Can execute dynamic web pages faster than CGI or Prel. Compared with other programming languages, PHP embeds programs into HTML documents for execution, and its execution efficiency is higher than CGI that completely generates HTML editing. Much higher, all CGI can be implemented
Supports almost all popular databases and operating systems
PHP can Use C, C++ to extend the program
##Advantages of PHP:
- Open source code
- Free sex
- Quickness
- Cross-platform strong
- High efficiency
- Graphics processing
- Professional focus
PHP technology application:
- Static page generation
- Database cache
- Process cache
- p+css
w3cStandard
- Big Load
- Distributed
- flex
- Support
- Smarty Module Engine
Junior IFE: Index Front Engineer Front-end Engineer
Intermediate IPE: Index PHP Engineer PHP Engineer Senior IAE: Index Architecture Engineer Architecture Engineer
6, echo, print_r, The difference between print and var_dump* echo、print是php语句,var_dump和print_r是函数
* echo 输出一个或多个字符串,中间以逗号隔开,没有返回值是语言结构而不是真正的函数,因此不能作为表达式的一部分使用
* print也是php的一个关键字,有返回值 只能打印出简单类型变量的值(如int,string),如果字符串显示成功则返回true,否则返回false
* print_r 可以打印出复杂类型变量的值(如数组、对象)以列表的形式显示,并以array、object开头,但print_r输出布尔值和NULL的结果没有意义,因为都是打印"\n",因此var_dump()函数更适合调试
* var_dump() 判断一个变量的类型和长度,并输出变量的数值
7、HTTP status codeClick Check out the detailed explanation of HTTP status codes here
Common HTTP status codes:
200 - Request successful
301 - The resource (web page, etc.) is permanently escaped to other URL404 - The requested resource (web page, etc.) does not exist
505 - Internal server error
HTTP status code classification:
1** - Information, the request received by the server requires the requester to continue performing the operation
3** - Redirect, further action is required to complete the request
4** - Client error, the request contained a syntax error or the request could not be completed
5** Server error, an error occurred while the server was processing the request
8. What are magic quotesMagic quotes are a process that will automatically escape the data entering the PHP script. It is best not to escape when encoding but to escape as needed during runtime
9. How to obtain the client's IP (requires an int) and the code of the server's IP##Client: $_SERVER["REMOTE_ADDR"]; or getenv('REMOTE_ADDR')ip2long for conversion
Server side: gethostbyname('www.baidu.com')
##10. Use those tools for version control
cvs, svn, vss, git
11. Methods to optimize the database
MySQL databaseEight ways to optimize (classic must-see) Click to get
Select the most applicable field attributes, reduce the width of the defined fields as much as possible, and try to set the fields to NOTNULL, such as ' It is best to use ENUM for province' and 'gender'Use connection (JOIN) instead of subqueryUse union (UNION) instead of manually created temporary table
Transaction processingLock table and optimize transaction Processing
Apply foreign keys, optimize locked tables
Establish indexes
Optimize query statements
12. Have you ever used template engine? What is the name of the template engine used?
Smarty: Smarty is a very old PHP template engine. It was my initial choice for using templates in this language. Although it is updated less frequently and lacks some features of the new generation of template engines, it is still worth a look.
13. For high-traffic websites, what methods should be used to solve the traffic problem
Confirm whether the server hardware can support the current traffic
Separate reading and writing of database, optimize data tables
Program function rules, prohibit external hot links
Control the download of large files
Use different hosts to divert main traffic
14. What is the difference between statements include and require? To avoid including the same file multiple times, you can use (?) statements to replace them
require is an unconditional inclusion, that is, if require is added to a process, it will be executed first regardless of whether the condition is true or not. require, when the file does not exist or cannot be opened, an error will be prompted and the program execution will be terminated
include has a return value, but require does not (probably because require is faster than include), if it is included If the file does not exist, an error will be prompted, but the program will continue to execute
Note: Included filerequire is fatal when it does not exist or has a syntax error, but include is not
require_once indicates that it is included only once, avoiding repeated inclusion
15. Talk about the understanding of mvc
The application is completed by the model, view, and controller. The model sends the functions to be implemented to the controller, and the controller receives the organizational functions and passes them to the view
16. Explain the difference between passing by value and passing by reference in PHP, and explain when passing by reference when passing by value?
Variables are always assigned by value by default, that is to say, when the value of an expression is assigned to a variable, the value of the entire expression is assigned to the target variable, which means Note: When one variable is assigned to another variable, changing the value of one variable will not affect the other variable
php also provides another way to assign values to variables: reference assignment. This means that the new variable simply references (in other words, becomes an alias or points to) the original variable. Changes to new variables will affect the original variables and vice versa. Using reference assignment, simply add an & symbol before the variable to be assigned (source variable)
The object defaults to pass-by-reference
For larger data, it is better to pass-by-reference. This can save memory overhead
The above is the detailed content of Summary of the latest classic PHP interview questions (Part 1). For more information, please follow other related articles on the PHP Chinese website!

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft