[One question per day] Are you often asked during php interviews?

, <?php echo count(strlen("http://php.net")); ?> What is the execution result?

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, it returns 1 . Normally returns the number of elements or attributes in var .

 

2. What should I pay attention to when using the list() function? 

Answer: list() is a grammatical structure. List($array) is used to quickly assign the elements in the array to some variables. Note that when using it, $array must be an index array, and the index value starts from 0 .

  

3. Please explain which functions are affected after safe_mode in php.ini is turned on?

Answer: Safe_mode is the safe mode of php . After opening, it will mainly affect the system operation, file, permission setting and other methods , mainly used to deal with webshell. The following are some of the functions 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 should be noted that safe_mode is deprecated in versions above php5.3, and this feature is completely removed in versions above php5.4.


4. Please give an analogy description of the main functions of the two regular expressions in POSIX style and compatible with Prel style.

Answer: POSIX  style  match regular expression ereg   and replace  ereg_replace

  Prel style: match regular expression  preg_match   and replace  preg_replace

The execution efficiency of  Preg_match  is faster than ereg , and the execution efficiency of preg_replace  is faster than ereg_replace .

 

5. How to run php script under command (write two ways) and how to pass parameters to php script?

Answer: The first way: first enter the php installation directory and execute  php  path / file name.php .

例:php my_script.php     php -f  "my_script.php"

The second way: php -r "php script "; ( no need to add php start and end symbols ) .

例:php -r "print_r(get_defined_constants());"

Pass parameters to the php script:

The first way: php -r "var_dump($argv);" - -h   ( Note: If the parameter to be passed starts with - , then the parameter list separator  can be used to pass the parameters correctly. )

The second way: test.php file code: #!/usr/bin/php <?phpvar_dump($argv);?>

    ./test .php  -h - foo ( in php added to the beginning of the file ! # / usr / bin / php , can be passed directly to - beginning with the parameters obtained )

 

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

answer:

1. __construct()  : Called automatically when the object is instantiated. 

2. __destruct()  : It is automatically called when the object is destroyed or the script execution ends.

3. __call()  : Execute this function when calling a method that does not exist in the object.

4. __get()  : Execute this function when getting the non-existent attributes of the object.

5、__set() :设置对象不存在的属性时执行此函数。

6、__isset() : 检测对象的某个属性是否存在时执行此函数。

7、__unset() :销毁对象的某个属性时执行此函数。

8、__toString() :将对象当作字符串输出时执行此函数。

9、__clone() :克隆对象时执行此函数。

10、__autoload() :实例化对象时,当类不存在时,执行此函数自动加载类。

11、__sleep() serialize之前被调用,可以指定要序列化的对象属性。

12、__wakeup unserialize之前被调用,可以执行对象的初始化工作。

13、__set_state() :调用var_export时,被调用。用__set_state的返回值做为var_export的返回值。

14、__invoke() :将对象当作函数来使用时执行此方法,通常不推荐这样做。

 

7、简述php的垃圾收集机制。

答案:php中的变量存储在变量容器zval中,zval中除了存储变量类型和值外,还有is_refrefcount字段。refcount表示指向变量的元素个数,is_ref表示变量是否有别名。如果refcount0时,就回收该变量容器。如果一个zvalrefcount1之后大于0,它就会进入垃圾缓冲区。当缓冲区达到最大值后,回收算法会循环遍历zval,判断其是否为垃圾,并进行释放处理。

关于此问题(http://blog.csdn.net/niluchen/article/details/9468365)有各为详细的讲解!

 

8、php实现一个双向队列。

队列是一种线性表,按照先进先出的原则进行

单向队列:只能从头进,从尾出

双向队列:头尾都可以进出

class DuiLie {
private $array = array();//声明空数组
public function setFirst($item){
return array_unshift($this->array,$item);//头入列
}
public function delFirst(){
return array_shift($this->array);//头出列
}
public function setLast($item){
return array_push($this->array,$item);//尾入列
}
public function delLast(){
return array_pop($this->array,$item);//尾出列
}
public function show(){
var_dump($this->array);//打印数组
}
public function Del(){
unset($this->array);//清空数组
}
}

 


以下是商务合作


下面给大家推荐一个人,也是业内的大咖,对我的技术也有不少帮助,相信对你们的帮助也应该不小。我也看了他给我推荐的不少视频资料,学习资料,非常的全面!应该都是最前沿的了,你在网上其他任何地方都找不到的,全是实战。其实看了他给的这些资料以后,拒绝花钱报名培训班。【下面是他给我的资料部分截图】


图片


Guess you like

Origin blog.51cto.com/15127568/2667219