One set of PHP interview questions-php Tutorial

Source: Internet
Author: User
Tags sesion
One set of PHP interview questions 1. the Statement include and require can include another file to the current file. The difference between them is ___. to avoid including the same file, which of the following statements can be used to replace them.


1. when the PHP program executes require (), it will only read the file once, so it is often placed at the beginning of the program. after the file is introduced, PHP will recompile the webpage file, make the introduced file a part of the original webpage. 2. when the PHP program executes include (), the file is read every time. Therefore, it is often used in the process control section, such as condition judgment or loop. 3. require (): unconditional inclusion. if the file does not exist, a fatal error is reported. script stop execution 4. include (): conditional inclusion. if the file does not exist, a warning is provided, but the script continues to be executed. 5. we recommend that you use require_once () and include_once (), it can detect whether the file contains duplicates.




2. what is the difference between get and post submission methods in a form?


The POST method is suitable for sending a confidential (such as a credit card number) or a large amount of data to the server, but the speed is slow. The Get method attaches the data to be transmitted to the URL and then delivers the data to the server together. Therefore, the transmitted data volume is limited and insecure, but the execution efficiency is better than that of the Post method. Specifically:
1. Get adds the data in the form to the URL pointed to by action in the form of variable = value, and the two use "?" And each variable is connected by "&". Post puts the data in the form data body and passes the data to the URL indicated by the action according to the corresponding variables and values.
2. Get is insecure because data is stored in the request URL during transmission, nowadays, many existing servers, proxy servers, or user proxies record the request URL to a log file and place it in a certain place, so that some private information may be seen by a third party. In addition, you can directly view the submitted data in the browser. some internal messages are displayed in front of the user. All Post operations are invisible to users.
3. Get transmission has a small amount of data, mainly because it is restricted by the URL length; while Post can transmit a large amount of data, so only Post can be used for uploading files (of course, there is another reason, as mentioned later ).
4. Get restricts that the dataset value of Form forms must be ASCII characters, while Post supports the entire iso000046 character set.
5. Get is the default Form method.




3. What is the difference between foo () and @ foo?


PHP supports an error control operator :@. Before placing the expression in a PHP expression, any error information that may be generated by the expression is ignored.
Note: The @ operator is only valid for expressions. A simple rule for beginners is: if you can get a value from somewhere, you can add the @ operator before it.
For example, you can place it before variables, functions, include () calls, constants, and so on. It cannot be placed before the definition of a function or class, nor can it be used for condition structures such as if and foreach.




4. what is the difference between = and = in PHP?


===Will compare the types of two variables ~~
And ==only compare their values ~~~




5. briefly describe the differences between DIV elements and SPAN elements


They are both block-level elements, but span is an inline object.


For example:

Example 1

Example 1


The result is as follows: Example 1
Example 1
The second case 2 the second case 2
The result is as follows: Example 2, example 2


You can understand that the default width of p is 100%, while that of span is not.
The most obvious difference is that DIV is a block element, and SPAN is an embedded element. The block element is equivalent to adding one
Line Feed. In fact, the block element and the row element are not static. as long as the block element is defined as display: inline, the block element becomes an embedded element. Similarly, the embedded element is defined as display: block becomes a block element.




6. what is the difference between Isset () and empty? What are the results of different data judgments?
$ A = 0; $ a = '0'; $ a = "; $ a = false; $ a = null;


Isset determines whether a variable exists. If yes, true is returned. empty determines whether the variable is null. If yes, true is returned.
Isset judgment: true, true, false.

Empty: true, true.




7. what is the difference between passing a value in php and transferring a reference? When will the value be passed for reference?


Pass value: modification to the transfer variable in the function does not affect the value of the passed variable (re-assign a value to the variable in the function using the transfer value)
Reference: transfers the reference of a variable. any operation in the function is equivalent to an operation on the transferred variable. the transfer of large variables has a high validity rate!




8. differences between echo (), print (), and print_r ()


Echo is a PHP statement, print and print_r are functions, and the statement does not return values. the function can return values (even if it is not used)
Print can only print values of simple type variables (such as int and string)
Print_r can print values of complex types of variables (such as arrays and objects)




9. what is the difference between Sort () assort () ksort? Under what circumstances are they used?


Sort () is sorted alphabetically by the values of elements in the array. The index key is numbered from 0 to n-1. It is mainly used to sort the array when the value of the array index key is irrelevant.
Assort (), PHP does not have the assort () function, so it may be asort. Asort () is used to sort arrays. the indexes of arrays are associated with units. It is mainly used to sort the arrays that are very important to the unit order.
Ksort () is used to sort index keys in alphabetical order based on the index key values in the array.




10. what is the difference between Mysql_fetch_row () and mysql_fetch_array?


The two functions return an array. The difference is that the array returned by the first function only contains values. we can only $ row [0], $ row [1], in this way, the data is read by the array subscript, while the array returned by MySQL_fetch_array () contains both the first and key-value pairs. we can read the data in this way, (assume that the database field is username, passwd ):


$ Row ['username'], $ row ['passwd']






11. what is the difference between mysql storage engine myisam and innodb?


The main difference between the two types is that Innodb supports transaction processing and foreign keys and row-level locks. MyISAM is not supported. Therefore, MyISAM is often considered only suitable for small projects.
The MyISAM type does not support advanced processing such as transaction processing, whereas the InnoDB type does. MyISAM tables emphasize performance, and the execution speed is faster than that of InnoDB, but transactions are not supported. InnoDB provides advanced database functions such as transaction support and external keys.




12. what is the difference between an abstract class and an interface class?
1. Methods in abstract classes can be implemented, but the methods in interfaces can only be declared.


2. the interface is the result of the design.
Abstract class is the result of refactoring


3. the interface is a special abstract class. in particular, all methods in the interface are abstract methods, and the attributes in the interface can only be static final constants.
1. the interface is a standard, and the abstract class is a template design.
2. all methods in the interface are abstract methods, and methods can be implemented in abstract classes.
3. static methods cannot be defined in interfaces, but in abstract classes.
4. all the variables in the interface are static constants. the abstract class can contain common variables.
5. constructor and initialization block cannot exist in the interface, but can be in the abstract class.
6. a class can implement multiple interfaces, but can inherit only one abstract class.






13. what is the difference between Cookie and session? can the session be used normally after cookies are disabled? What are the disadvantages of session? Where does a session exist on the server? Are they Common or private?


1. cookie data is stored in the client's browser, and session data is stored on the server. 2. cookies are not very secure. others can analyze the cookies stored locally and perform cookie spoofing. for security reasons, session should be used. 3. the session will be stored on the server for a certain period of time. When the number of access requests increases, it will occupy the performance of your server. to reduce the performance of your server, you should use cookies. 4. data stored in a single cookie cannot exceed 4 kB. many browsers limit that a site can store up to 20 cookies. The premise of sesion is that the browser supports cookies. when a user visits a website for the first time, there is no session ID in the cookie. then, the server writes the sesion ID to the cookie, which will be obtained from the cookie for each access. however, if the user's browser does not support cookies, no session ID is provided for each request, and the server considers the user as a different user each time, there is no way to save the user's previous operation results on the server.




14.-> and: differences between operators


Class static methods and reference methods of static properties
For example
Class Test {
Public static $ test = 1;
Public static function test (){
}
}


You can directly use Test: $ test to obtain the value of the $ test attribute without instantiating an object.
Static method call is also the same as Test: test (); directly call the static method test.


When accessing the member variables or methods in the PHP class, if the referenced variables or methods are declared as const (defining constants) or static (declaring static), the operator must be used:: if the referenced variable or method is not declared as const or static, the operator-> must be used.


In addition, if you access const or static variables or methods from the inside of the class, you must use self-referenced. Otherwise, if the internal access from the class is not a const or static variable or method, then you must use the self-referenced $ this.

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.