Interview Questions and answers I met (1), Interview Questions and answers

Source: Internet
Author: User
Tags php error

Interview Questions and answers I met (1), Interview Questions and answers

 

1. <? Php echo count (strlen ("http://php.net");?> ?

Answer: 1

Description: count (var) is used to count the number of elements in an array or object. When var is null or an empty array, the result is 0. If var is a common variable, 1 is returned. Normally, the number of elements or attributes in var is returned.

 

2. Which functions are affected after safe_mode is enabled in php. ini?

Answer: Safe_mode is the php security mode. After it is enabledSystem operations, files, and permissionsAnd other methods, mainly used to cope with webshell. The following are some affected functions:Ckdir, Move_uploaded_file, chgrp, parse_ini_file,

Chown,Rmdir,Copy, Rename,Fopen,Require, Highlight_file,Show_source,Include, Symlink, link, touch,Mkdir, Unlink, exec,

Shell_exec, pasathru,System, Popen

Note that safe_mode is discarded in php5.3 or later versions. In php5.4 or later versions, this feature is completely removed.

 

3. What are the magic methods in php5? Please give examples to illustrate their respective usage.

  • _ Construct (): constructor. This method is called when an object is created. The advantage of this method is that the constructor has a unique name, no matter what the name of its class is. in this way, you do not need to change the name of the constructor when changing the class name.
  • _ Destruct (): destructor. PHP will call this method before the object is destroyed (that is, before it is cleared from memory. By default, PHP only releases the memory occupied by Object Attributes and destroys object-related resources.
  • _ Call (): this function is executed when the method of calling an object does not exist. Including methods with no access permissions
  • _ Get (): Access this method when an undefined property is called.
  • _ Set ($ property, $ value): called when an undefined property is assigned a value.
  • _ Isset (): This method is called when the isset () function is called on an undefined property.
  • _ Unset (): This method is called when the unset () function is called on an undefined property.
  • _ ToString (): The toString method is automatically called when an object is converted to a string. For example, when an object is printed using echo
    If the class does not implement this method, the Object cannot be printed using echo; otherwise, the following error occurs: Catchable fatal error: Object of class test cocould not be converted to string in.
    This method must return a string
  • _ Clone (): execute this function when cloning an object. Object assignment in PHP5 is a reference assignment. If you want to copy an object, you need to use the clone method. When you call this method, the object will automatically call the _ clone magic method. If you need to perform some initialization operations on Object replication, You can implement them in the _ clone method.
  • _ Autoload (): it is automatically called when trying to use a class that has not been defined. By calling this function, the script engine has the last chance to load the required class before a PHP error fails.

Note: The exception thrown in the _ autoload function cannot be caught by the catch statement block and cause a fatal error.

  • _ Sleep (): called before serialize. You can specify the object attribute to be serialized.
  • _ Wakeup: called before unserialize. You can initialize an object.
  • _ Set_state (): called when var_export is called. Use the return value of _ set_state as the return value of var_export (effective from PHP 5.1.0 ).
  • _ Invoke (): This method is usually not recommended when an object is used as a function.
  • _ CallStatic it works in a way similar to _ call () magic method, __callstatic () is used to handle static method calls

 

4. Several frequently used super global variables.

  • $ _ GET -----> get Transmission Method

  • $ _ POST -----> post Transmission Method

  • $ _ REQUEST -----> you can receive get and post values.

  • $ GLOBALS -----> put all the variables in it

  • $ _ FILES -----> used to upload FILES

  • $ _ SERVER -----> system environment variables

  • $ _ SESSION -----> used in SESSION control

  • $ _ COOKIE -----> used for session control

 

5. Let's talk about some design patterns you know.

  • Singleton mode: ensures that a class has only one instance, and provides a global access point to access it, such as a database connection in the framework.

  • Policy mode: for a group of algorithms, each algorithm is encapsulated into an independent class with a common interface. For example, when you enter the personal homepage, different display and operations are performed based on the browser.

  • Registration mode: provides the ability to systematically store and manage a group of global objects in a program, such as Zend_Registry: set in the ZF framework.

  • Adapter mode: Adapt different interfaces to a unified API. For example, data operations include mysql, mysqli, and pdo. You can use the adapter mode to unify interfaces.

  • Observer mode: an object can be observed by adding a method. When an observed object changes, the message is sent to the registered observer. For example, message pushing

  • Decorator mode: dynamically extends the class functions without modifying the original class code and inheritance. For example, each Controller file in the framework provides the before and after methods.

  • Iterator mode: provides a method to access each element of an aggregate object sequentially, and inherits the Iterator class in PHP.

 

6. Write a function to verify that the email format is correct.

<? Php $ str = "jianfeng@126.com"; regex = "([a −z0 −9 \. −] +) @ ([\ da −z \. −] + )\. ([a −z \.] 2, 6) "; // regular return preg_match (regex, str);?>

 

7. Differences between isset, empty, and is_null.

  • Isset determines whether the variable is defined or empty
  • Empty: determines whether the variable value is null. If it can be converted to false, all values are null. If it is null, true is returned. Otherwise, false is returned.
  • Is_null: checks whether the input value (value, variable, expression) is null.
8. For relational databases, indexing is a very important concept. Please answer several questions about indexing: a) What is the purpose of indexing?
  1. Quick access to specific information in a data table to improve retrieval speed

  2. Create a unique index to ensure the uniqueness of each row of data in the database table.

  3. Accelerate the connection between tables

  4. When you use grouping and sorting clauses to retrieve data, you can significantly reduce the time for grouping and sorting in queries.

B) What is the negative impact of indexes on the database system?

Negative impact:
It takes time to create and maintain indexes. This time increases with the increase of data volume. Indexes require physical space, not only for tables, but for each index; when adding, deleting, modifying, and modifying tables, indexes must also be dynamically maintained, which reduces the Data Maintenance speed.

C) What are the principles for creating an index for a data table?
  1. Create an index on the most frequently used field to narrow the query range.

  2. Create an index on frequently used and sorted Fields

D) under what circumstances should indexes not be created?

 

9. What are the main attack methods for PHP websites?

10. If the name column may be null in the result returned by the following statement, which function can be used in the name field to change the null value to a default value.

SELECT a.id,b.name FROM tab1 AS a LEFT JOIN tab2 AS b ON(a.id = p.id) WHERE a.id > 10;

A:

SELECT. id, IFNULL (B. name, 'undefined ') FROM tab1 AS a left join tab2 AS B ON (. id = p. id) WHERE. id> 10;

See the explanation in the official manual: IFNULL (expr1, expr2 ). If expr1 is not NULL, IFNULL () returns expr1; otherwise, it returns expr2. IFNULL () returns a number or string value, depending on the context in which it is used.

However, in my tests, there is a problem when expr1 = 0 instead of null. He also returned expr2; the official manual should be changed to return expr2 when expr1 is null or 0.

 

 

Now, let's update these 10 items in the first phase. I hope to help my friends find their desired jobs. Please pay attention to "My Interview Questions and answers (2 )".

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.