PHP programmers are frequently asked questions in the interview "reprint"

Source: Internet
Author: User
Tags php script

1. What is the difference between Include and require, the efficiency of require and require_once?

PHP explained once when encountering include, if the page appears 10 times include,php explained 10 times, and PHP encountered require only once, even if the page appears more than once require is explained only once, As a result, require's performance is higher than include.

PHP uses require to include files as part of the current file, if there is a syntax error in the included file or the contained file does not exist, then the PHP script will no longer execute and prompt for errors.

PHP uses the Include file to specify the path of the file, when the contained file has a syntax error or the contained file does not exist when the warning, does not affect the operation of its own script.

Include can tell if a file is included when it is included, and require is included in any case.

The efficiency of require is more efficient than require_once because the require_once determines whether the file is included when the file is included.

2. What is the difference between a cookie and a session that prohibits a cookie from being used properly after the session? What is the disadvantage of the session? Where does the session exist on the server side? Is it common or private?

The cookie is stored on the client, and the user can modify it by means of the device, which is unsafe and the maximum allowable value for a single cookie is 3k. And the session is saved on the server side, relatively safe, size is not limited. The session with the cookie disabled cannot be used properly.

The disadvantage of the session: to protect the server side, each read from the server to read, the server has resource consumption.

The session is saved in the file or database on the server side and is saved by default in the file, and the file path is specified by Session.save_path of the PHP configuration file.

The session file is public.

3. How do I prevent SQL injection?

1. Filter out some common database operation keywords: select,insert,update,delete,and,*, etc.

or through the system functions: addslashes (content that needs to be filtered) to filter.

2. In the PHP configuration file

Register_globals=off; set to OFF state//effect will register global variable close.

For example: receive the value of the POST form using $_post[' user '], if register_globals=on; directly use $user to receive the value of the form.

3. When writing SQL statements, try not to omit the Kohiki number (the TAB key above) and the single quotation mark

4, improve the database naming skills, for some important fields according to the characteristics of the program named, take not easily guessed

5, for common methods to encapsulate, avoid direct burst SQL statement

6. Open PHP Security mode

Safe_mode=on;

7. Open MAGIC_QUOTES_GPC to prevent SQL injection

Magic_quotes_gpc=off, which is turned off by default, will automatically convert the query of the SQL statement submitted by the user to the ' to \ ', which has a significant effect on preventing SQL injection.

So open: Magic_quotes_gpc=on;

8. Control error Messages

Close the error message and write the error message to the system log.

9, using mysqli or PDO pretreatment.

4. There are several types of database indexes, what are the respective? When should I use an index?

Normal index, primary key index, unique index

Not all databases use the index in the same way, and as a general rule, you need to create an index on the table only if you frequently query the data in the column.

5. What is the difference between a reference and a non-reference value, and when should I use a reference to pass a value? When should I use a non-reference value?

Pass by value: changes to values within the function range are ignored outside the function.

Pass by reference: Any changes to values within the function scope will also reflect those changes outside of the function.

When passing by value, PHP must copy the value, which would be a costly operation if it was manipulating large objects and strings. Passing by reference does not require copying values, so it is beneficial to improve performance.

When you need to change the value of a source variable within a function, pass it with a reference if you do not want to change the value of the original variable by passing a value.

6. Write a few magic methods and explain the role?

__call () method that is called automatically when a method that does not exist is called

__autoload () Instantiates a class that is not yet defined and automatically calls the secondary method to load the class file

__set () method that is automatically called when a value is assigned to an undefined variable

__get () method that is called automatically when you get the value of an undefined variable

__construct () constructor method that is called automatically when the class is instantiated

__destroy () methods that are called automatically when objects are destroyed

__unset () method that is called automatically when unset () is called on an undefined variable

__isset () method that is called automatically when the Isset () method is called on an undefined variable

__clone () clones an object

__tostring () method that is called automatically when an object is output

7. What is the meaning of $_request, $_post, $_get, $_cookie, $_session, and $_file?

They are all pre-defined variables of PHP.

$_request used to get the value of a post or Get method submission

$_post used to get the value of the Post method submission

$_get used to get the value submitted by the Get method

$_cookie used to get the value stored by the cookie

$_session used to get the value of Session store

$_file used to get the value of the upload file form

8. What is the best type of subscript in an array, and why?

The subscript of an array is preferably a numeric type, and the processing speed of the numeric type is fast.

9. ++i and i++ which one is high efficiency, why?

++i efficiency is more efficient than i++ because ++i is less a process of returning I.

10. What is the meaning of MAGIC_QUOTES_GPC (), Magic_quotes_runtime ()?

MAGIC_QUOTES_GPC () is a PHP configuration file, and if set to on, automatically escapes the string in the Post,get,cookie, before adding \

Magic_quotes_runtime () is a function in PHP, and if the argument is true, the single quotation marks, double quotes, and backslashes that are taken out of the database are escaped with a backslash.

What is the difference between 11.Echo (), print (), Print_r ()?

Echo () is a PHP syntax that can output multiple values and cannot output an array.

Print () is the language structure of PHP and can output variable values of a single simple type.

Print_r () is a PHP function that prints out the values of complex type variables, such as arrays, objects.

12. Talk about your understanding of MVC.

MVC is a design pattern that enforces the separation of input, processing, and output, and the three core parts of MVC: M-model, V-View, C-Controller.

A view is the interface that the user sees and interacts with.

A model is a data business rule for a program.

The controller receives the user's array of call models and views to complete the user's requirements.

Advantages of using MVC: Low coupling, high reusability, low life cycle cost, rapid development deployment, maintainability, scalability, and benefit of software engineering management.

The disadvantage of MVC: there is no clear definition, and full understanding is not easy. Small projects are not suitable for MVC.

13. What are the advantages and disadvantages of single entry and multi-entry in the framework?

Multi-entry is the completion of user requests by accessing different files.

Single entry only Web applications all requests are directed to a script file.

A single portal makes it easier to control permissions, allowing for security checks on HTTP requests.

Cons: URLs look less beautiful, especially unfriendly to search engines.

14. Print one with '. ' Linked strings, what else can be used instead of '. ' More efficient links?

can be used, instead., more efficient.

15. What does the hint type 200, 404, 502 mean?

200 is the request succeeds, 404 is the file is not found, and 502 is the server internal error.

16. Write a custom function to extract the suffix name of this path.

"Www/hello/test.php.html?a=3&b=4"

Function Geturltype ($url) {

$info =parse_url ($url);

Return End (Explode ('. ', $info [' path ']);

}

17. What are the advantages of your understanding of Memcach?

Memcache is a caching technique that, after parsing a dynamic Web page for a certain amount of time, is saved to a file, and the next time it is accessed, the Dynamic Web page calls the file directly without having to re-access the database. The advantage of using memcache for caching is to increase the access speed of the website and reduce the pressure on the server when high concurrency occurs.

Advantages of Memcache: Stable, simple configuration, multi-machine distributed storage, fast

PHP programmers are frequently asked questions in the interview "reprint"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.