PHP basics are ignored

table of Contents

Continuously updated record of some concern.

  1. The following PHP configuration items, which are not relevant and most secure :()
A. open_basedir
B. register_globals
C. disable_functions
D. file_uploads

open_basedir can range limit active user access to files in the specified area, usually a path to their home directory, also available symbols. "" to represent the current directory. Note the limit specified with open_basedir is actually a prefix, not a directory name. For example: If the "open_basedir = / dir / user", then the directory "/ dir / user" and "/ dir / user1" are accessible. So if you want to restrict access to only the specified directory, end with a slash path names. Arranged, for example: "open_basedir = / dir / user /"

register_globals means that registered as global variables, so when On when the passed value will be directly registered as global variables directly, while the Off time, we need to go get it at a particular array. 1.PHP 4.2.0 version of the file in the default value for register_globals changed from on off, although you can set it to On, but when you can not control the server, your code compatibility has become a big problem Therefore, you'd better start now with the start of the programming style Off. 2. When, register_globals variables are injected code, such as variable requests from the HTML form. Coupled with PHP before use does not require variable initialization, which makes the code easier to write unsafe. When on, people use variables variable does not know where they come from, and can only assume. Disabling register_globals worst case change variables and internal variables such code sent by the client mixed together.

disable_functions limit some functions may be performed using the program system commands directly, such as system, exec, passthru, shell_exec, proc_open like. So if you want to ensure the security server, set this function will be added to disable_functions in safe mode or open it

file_uploads, PHP file upload feature to record file_uploads decide whether to enable command, the default values: On.

  1. The following result of the program :()
   <?
          $str = "LAMP";
          $str1 = "LAMPBrother";
          $strc = strcmp($str,$str1);
          switch ($strc){
                 case 1:
                        echo "str > str1";
                        break;
                 case –1:
                        echo "str < str1";
                        break;
                 case 0:
                        echo "str = str1";
                        break;
                 default:
                        echo "str <> str1";
          }
   ?>
   
A. str > str1
B. str < str1
c. str = str1
D. str <> str1

strmp ( \ (str1, \) str2) function means, comparing two strings, the two strings is calculated when compared to the number of phase difference (different) character together as a return. The result is -7.

  1. The output of the operation code ()
<?php
   $d=mktime(9, 12, 31, 6, 10, 2015);
    echo "创建日期是 " . date("Y-m-d h:i:sa", $d);

A. creation date is 2015-06-10 09:12:31 am

B. creation date is 2015-10-06 09:12:31 am

C. creation date is 2015-10-6 9:12:31 am

D. creation date is 2015-10-06 09:12:31 pm

mktime — 取得一个日期的 Unix 时间戳;  即:时,分,秒,月,日,年。
int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int$month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )
  1. In object-oriented PHP, the following description of the error on the final modifier is ()

A. Use the final identification of the class can not be inherited

B. Using the method of final identification members in the class, can not be overridden in a subclass

C. can not be used to identify members of the final property

D. Using the member attribute final identification and can not be redefined in a subclass

PHP 5 新增了一个 final 关键字。如果父类中的方法被声明为 final,则子类无法覆盖该方法。如果一个类被声明为 final,则不能被继承。
Note: 属性不能被定义为 final,只有类和方法才能被定义为 final。
  1. The data type returned by the function value getdate () :( a)

Shaping B. A. D. array of floating-point string C.

调用getdate函数的返回值
Array ( [seconds] => 37 [minutes] => 34 [hours] => 15 [mday] => 19 [wday] => 3 [mon] => 8 [year] => 2015 [yday] => 230 [weekday] => Wednesday [month] => August [0] => 1439969677 )
  1. About mysql_pconnect statement is correct? ()

A. B. multi-connection with the database with the same function mysql_connect function the same as D. C. and @mysql_connect a persistent connection to the database

mysql_pconnect() 函数打开一个到 MySQL 服务器的持久连接。

mysql_pconnect() 和 mysql_connect() 非常相似,虽然只多了一个P, 但有两个主要区别:

当连接的时候本函数将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的(持久)连接,如果找到,则返回此连接标识而不打开新连接。其次,当脚本执行完毕后到 SQL 服务器的连接不会被关闭,此连接将保持打开以备以 后使用( mysql_close() 不会关闭由 mysql_pconnect() 建立的连接)
  1. Look at the code, the database will shut off command which identifies the connection? ()
   <?php
       $link1 =mysql_connect("localhost","root","");
       $link2 = mysql_connect("localhost","root","");
       mysql_close();
   ?>

A. $ link1 B. $ link2 C. D. Close All error

【就近原则】
mysql_close() 关闭指定的连接标识所关联的到 MySQL 服务器的非持久连接。
如果没有指定 link_identifier,则关闭上一个打开的连接。

bool mysql_close ([ resource $link_identifier = NULL ] )
  1. Read the following code to answer output.
<?php
$data = ['a','b','c'];

foreach ($data as $k => &$v){
    //
    
}

var_dump($data);


foreach ($data as $k => $v){
    //
    
}

var_dump($data);

The first output [ 'a', 'b', 'c']

The second output [ 'a', 'b', 'b']

The first time through the use of address reference points to an array of $ v final position, namely the position of c;

Assign values to the second pass \ (v, a value is assigned to \) V, point c, this time a [2] = a; perform a second element, b is assigned to \ (v, assigned \) point to the address v a [2], In this case the array a [2] = b; perform a third element, then a [2] = b, b assigned \ (v, assigned \) v at the address, this an array a [2] = b

  1. Read the code, answer them.
<?php

class A{
    
    public static function who(){
        
        echo __CLASS__;
        
    }
    
    
    public static function test(){
        
        static::who();
        
    }
    
     public static function test2(){
            
        self::who();
     }
}


class B extends A{
    
    public static function who(){
        echo __CLASS__;
    }
}

B::test();    //B  static指向调用方B,用于后期静态绑定,也可以称之为“静态绑定”,因为它可以用于(但不限于)静态方法的调用。
B::test2();   //A  self指向其定义所在类

Starting from PHP 5.3.0, PHP adds feature called late static binding, used to refer to a static class called within the scope of inheritance.
When a static method call, that (typically :: operator left side portion) is the class name explicitly specified; when the non-static method invocation, the class that is taken from the object belongs ------ php.net

Late static binding would like to bypass this limitation by introducing a new class represents the initial call to run keyword. Simply put, this keyword allows you to call in the above example cited when test () is a class B instead of A.
The final decision not to introduce a new keyword but rather use static keyword that has been reserved. ------ taken from php.net

Another use of static case:

<?php
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        static::who(); // 后期静态绑定从这里开始
    }
}

class B extends A {

}
?>

B::test();   // A 因为B类中没有who方法,所以不得不又调用A类中的who方法。
  1. Read the code, answer them.
<?php
class A {
    public static function  who(){
        
        echo __CLASS__;
        
    }
  
}


class B extends A {
    
    public static function who(){
        
        echo __CLASS__;
        
    }
    
     
}

class C extends B{
    public function who(){
        
        echo __CLASS__;
        
    }
    
     public static function test(){
            A::who();     //A
            parent::who();  //B
            self::who();    //C
            static::who();  //C
        }
}

C::test();

Guess you like

Origin www.cnblogs.com/followyou/p/11404013.html