8 PHP Surface Questions How much you know about PHP

Source: Internet
Author: User
Tags ereg posix
PHP face a variety of questions, I also introduce you to the PHP interview questions in the pen questions, core technical questions, thinkphp questions, easy to wrong questions. This is what we will encounter in the interview, recently found a very interesting thing, a lot of companies out of the PHP surface test can directly reflect the PHP level, then we take you today to see what is the PHP surface of the question can reflect the extent of PHP understanding!

1.

<?php echo Count (strlen ("http://php.net"));?>

What is the result of the execution?

Answer: 1

Explanation: 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 normal variable, 1 is returned. Returns the number of elements or attributes in Var under normal conditions.

2. What do I need to pay attention to using the list () function?

Answer: List () is a grammatical structure. The list ($array) is used to quickly assign elements in an array to variables. When used, be aware that $array must be an indexed array, and the index value starts at 0.

3, please explain the php.ini in the Safe_mode after the impact of what functions?


Answer: Safe_mode is a safe mode for PHP. After opening, mainly to the system operation, file, permission settings and other methods have an impact, mainly used to deal with Webshell. The following are some of the functions that are affected:

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

It is important to note that the Safe_mode is deprecated in php5.3 and above, and this feature is completely removed from the php5.4 version.

4. Describe the main functions of the two regular expressions, POSIX style and compatible prel style.

Answer: POSIX style: match regular expression Ereg and replace Ereg_replace

Prel style: match regular expression Preg_match and replace Preg_replace

Preg_match is more efficient than ereg, and preg_replace is faster than ereg_replace execution.

5, how to run a PHP script under the command (write out two ways), how to pass parameters to the PHP script?

Answer: The first way: Go to the PHP installation directory, execute PHP path/file name.

Cases:

PHP my_script.php     php-f  "my_script.php"

The second way: php-r "php script";(do not need to add PHP start character and Terminator).

Cases:

Php-r "Print_r (Get_defined_constants ());

To pass parameters to a PHP script:

The first way: Php-r "Var_dump ($ARGV);"---H (Note: If the argument to be passed begins with-, the argument list delimiter is used--to correctly pass the argument.) )

The second way: test.php file code:

#!/usr/bin/php  <?phpvar_dump ($ARGV);? >

./test.php-h-Foo (add #!/usr/bin/php at the beginning of the PHP file, you can pass it directly to the start parameter)

6. What are the magic methods in PHP5? Please give examples of their usage.

Answer:

1, construct (): called automatically when instantiating an object.

2. Destruct (): Automatically called at the end of destroying the object or script execution.

3. Call (): Executes this function when the method that called the object does not exist.

4, Get (): Executes this function when getting an object that does not exist.

5, set (): Executes this function when setting a property that does not exist for an object.

6. Isset (): Executes this function when detecting whether a property of an object exists.

7. Unset (): Executes this function when destroying a property of an object.

8, ToString (): Executes this function when the object is exported as a string.

9. Clone (): Executes this function when cloning an object.

10. AutoLoad (): When instantiating an object, execute this function to automatically load the class when the class does not exist.

11, Sleep (): Serialize was called before, you can specify the object properties to serialize.

12, wakeup:unserialize before the call, you can perform initialization of the object work.

13, Set_state (): Called when Var_export is called. Use the return value of Set_state as the return value of Var_export.

14. Invoke (): Executes this method when the object is used as a function, which is generally not recommended.

7. Summarize the garbage collection mechanism of PHP.

Answer: Variables in PHP are stored in the variable container zval, in addition to storing variable types and values in Zval, there are is_ref and RefCount fields. RefCount represents the number of elements that point to a variable, and IS_REF indicates whether the variable has an alias. If RefCount is 0 o'clock, the variable container is recycled. If a zval refcount is greater than 0 minus 1, it goes into the garbage buffer. When the buffer reaches its maximum value, the recovery algorithm loops through the zval, determines whether it is garbage, and disposes of the process.

8. Implement a two-way queue with PHP.

A queue is a linear table that is based on the FIFO principle

One-way queues: can only be entered from the beginning, from the tail

Two-way queue: can be in and out of the tail

Class Duilie {Private $array = array ();//declare empty array public function Setfirst ($item) {return Array_unshift ($this->array,$ Item);//header into row}public function Delfirst () {return array_shift ($this->array);//Header dequeue}public function Setlast ($item) { Return Array_push ($this->array, $item);//tail into row}public function Dellast () {return Array_pop ($this->array, $item); /tail dequeue}public function Show () {var_dump ($this->array);//print array}public function Del () {unset ($this->array);//Empty Array}}

Summarize:

This article introduces you to the PHP interview questions are we are often encountered in the development work, so these questions can reflect how much you know about PHP, as well as the actual development of how much, so it is very intuitive PHP interview questions, I hope you have some help!

Related recommendations:

An analysis of object-oriented topics in PHP interview questions


One of the most error-prone 10 php face questions


PHP core technology problem sharing in an interview question


php Summary of written questions in interview questions

Related Article

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.