PHP Summary Notes

Source: Internet
Author: User
Tags echo date explode

First, PHP base syntax variable to array

  1 <?php 2//phpinfo ();  3 4/* Variable 5 $a =1;//unallocated space 6 echo "\ $a =". $a;  7 echo "<br/>"; 8 Var_dump ($a);//result is null 9 echo "Hello Worrld"; * * */* int type maximum can be expressed as a large echo "&lt ;br/> ". Php_int_size; echo "<br/>". php_int_max;//(2 of 31 square-1) 31:4*8-1 sign bit $a =-2147483648; echo "<br/>". $a; Var_dump ($a);//the range of type int is changed to float type */17 18/* Boolean value $d = 0.0;          if (! $d) {22}*/23 */* floating point 24 floating-point precision is 14 (starting from the left, the first non-0 is the beginning of precision) */25 26/* Character Type 27 28 single and double quotation marks $d = 90; $d 1= "$d"; $d 2= ' $d '; echo $d 1; echo $d 2;*///$a =7/5.1; Panax Notoginseng//echo $a; 38 39 # = = = include type also equal to/* $a = 2; $b = 2.0;  if ($a! = $b) (+-echo "! ="; 45} 46          if ($a!== $b) #!== include type is also not equal to {"echo"!== "; 49}*/50 51 /* && | | As long as the previous one is true or false that is not performed after a and and or is not the priority ratio = low so that the $e =false or true; The result is false, because at this point the $e is first assigned to False Var_dump ($e);            $f =true and false;//result is true, because at this point $e is first assigned true var_dump ($f); */58 59 */String concatenation 60 $a = "1"; $b = "2"; $c = $a. $b; 62 */63 64 * Object type operator dog{} $dog =new Dog; Var_dump ($dog instanceof Dog); $a = 3; Echo $a ++*3;//9*/72 73/* Constant define ("Tax_int", 21); # $TAX _int=9; Echo Tax_int; tax_two=0.3 const; echo "<br/>". Tax_two; * * * * */* #require ' other.php ';//will not determine whether the repetition, may lead to duplicate output require_once ' other.php ';//First determine if there is   Repeated introduction 84 85     #include ' 111other.php '; #include_once ' other.php ';        Differences between #require and include: #include如果出现了错误会继续执行, #而require则会终止程序 91 92 #echo "22"; 94 $i = 2; $result =getnum ($i);//Pass the value, you can also pass the address & echo $result; */97 98/* global variable $a = 1;            The function get () 101 {102 Global $a;//can be used in the local 103 $a ++;104}105        Get (); 106 echo $a; 107 */108 109/* Array initialization of//$array =array (1.2,12, "Wrwe", true); 111 echo Count ($array), 113 $arr =array ("Log" = "Daomul", "Mima" =>123); Echo Count ($arr )." <br/> ($arr as $key + $val) 117 echo $key. = ". $val."  <br/> "; 118}119 $arr 2=array (" "" = "+",1=> "FDSF", 23,23); 121 echo $arr 2[""]. " <br/> "; 122 echo $arr 2[2]."<br/>"; 123 124 #使用true作为下标, that is 1, false:0; Null: "" 126 $arr 3=array (123.4=> "ARR3"); 127 echo $arr 3[123]. " <br/> 129 #显示详细数组信息130 Print_r ($arr 3); echo "<br/>", 131 Var_dump ($arr 3), 133 #数组可以动态增长134 $arr 4=array (2,3); 1 Echo $arr 4[1]. "         <br/> "; 136 $arr 4[2]= ' one 333 444 '; 137 #echo $arr 4[2];138 139 #字符串的拆分 explode140  $arr =explode ("", $arr 4[2]), 141 print_r ($arr), 142 143 foreach ($arr as $key + $val) # (array to loop As array subscript variable) 144 {145 echo "<br/> $key = = $val"; 146}147 148 E             Cho "<br/>". $arr [1];149 unset ($arr [1]); #销毁数组元素后, the keyword subscript will not be re-populated print_r ($arr); */151 152/* Array Operation Overlay 153 $a =array ("a" =>12, "B" =>23) 154 $b =array ("a"=>21, "C" =>43); 155 $a = $a + $b; 156 print_r ($a); */157 158 159?> 

Second, array

1 

Third, static variables

1 <?php 2    3       class Child 4       {5 public           static $num =0, 6 public           $name; 7           function __construct ($na ME)//Only new can call 8           {9               $this->name= $name;               }11               //Static variable cannot use this to access the public           function join () +-Self               :: $num +=1;  Can: Child:: $num               Echo $this->name. " You ";       }18       $child 1=new Child ("K"),       $child 1->join (),       $child 1=new Child ("A"),       $child 1->join (),       $child 1=new Child ("B"),       $child 1->join (),       echo " <br/> ". Child:: $num;       +//class can only be  class name:: Variable,           in//class can be two kinds of?>

Iv. Inheritance/encapsulation/polymorphism/abstraction

  1/*class Child 2 {3 public static $num = 0;  4 public $name; 5//Construction Method 6 function __construct ($name)//Only new can call 7 {8 $this->name=$  Name               9} 10//Static variable cannot use this to access one public function join ($ifee) 12 {13  Self::ifee+=1; Can: Child:: $num echo $this->name. "  You "; $child 1=new Child ("K"); $child 1->join (); $child 1=new Child ("a"); $child 1->join (); $child 1=new Child ("B"); $child 1->join (); echo "<br/>". Child:: $num; 25//class can only be the class name:: Variable, 26//class can be two */27 28 29 30//static method can not adopt non-static variable, can only use non-static change The volume 31//member function calls each other, need to use $this->text (); 32 33//Inherit 34 35//1, subclass can inherit only one parent class 36//If you want multiple inheritance, consider inheriting multiple times: PNs/*class a{}, class B extends A {} ClasS C extends b{}*/40 41//2, the constructor in the parent class, when creating an object instance of a subclass does not automatically call 42//3, the method of calling the parent class in the subclass 43//Parent class Name:: Method Name (); /Parent:: Method name ();          Parent Lowercase 44 45//Overwrite: 46 # The method of the subclass and the method name of the parent class are exactly the same as the number of arguments, but do not require the same parameter name 47 # But the modifier can be different, but the range of the child 〉= the parent class range 48 # The parent class is private and cannot overwrite the/*class a{function F () {"echo" parent class here! <br/> "; The extends a{}, class C extends b{() () {Echo Using the parent class of <br/> "; Parent::f (); A::f (); ) $C 1=new C (); $C 1->f (); */64 65//Abstract class: The parent class does not need to be instantiated, only the subclass inherits, can also be called inside; to achieve code reuse #抽象类 abstract class name{ } #抽象方法 Abstract public cry (); #抽象类不一定也有抽象方法 #类包含抽象方法则必须为抽象类 #子类继承抽象父类, you must be an abstract class or implement all of the inherited, all! Method 72 73 74//interface: INTERFACDE interface {//attribute//method} 75 # can only define the specification, let the class to implement the interface, can not be implemented by itself, the # Class C I       Mplements Interface {} 77 # interface cannot be instantiated/interface can inherit other multiple interfaces/cannot fail to public 78 # A class implements an interface, must be the interface and the method of its inherited interface to implement all 79 # (more than 1 classes of the class to implement a function, but the implementation of different ways, there is no secondary  Commitment relationship, 80 # (2 Project manager set specifications, let other programmers realize the Bayi/*interface Stu (a=90)     Public function add ();  Interface stu2{} Mystu class implements STU,STU2. function Add () "dddd". Stu::a. " <br/> "; 94} $mystu =new Mystu (); $mystu->add (); echo "OK". stu::a;            #获得接口中的常量 */98//final The methods in the class are not overwritten by the # Final cannot decorate member properties 101/*class A102 {103         Final public function get ($salary) 104 {*3;106 return $salary}107}108 Class B extends A109 {public function get ($sal) 111 {return $s    al*2;        113}114}115    $b =new B (), $b->get ("21");            #Cannot Override final Method A::get () */117 118//const constant 119 # To assign an initial value; cannot be assigned later; Cannot add $ etc modifier 120 # self::a;  Class name:: A; Interface name:: A; The value of constant A is obtained by equal means.

V. File manipulation and error handling

 1 <?php 2 3//File operation 4/* Handling the wrong Way 1 5 if (!file_exists ("File1.txt")) 6 {7 echo "not here"; 8 exit () ; 9}10 else11 {$fp =fopen ("File1.txt", "R"); echo "File is open"; fclose ($FP); 15}*/16 17/* Processing The wrong way 218 if (!file_exists ("A.txt")) ("Wenjianbucunzai"),}22 else23 {}24 echo "end"; */25/* Processing The wrong way 126 file_exists ("B.txt") or Die ("Zhen de"); echo "End"; 29 */30 31//define error function./*function My_error ($  Error, $err _message) {<font size= ' 5 ' color= ' Red ' > $error </front><br/> ";//235//echo "The error message is:". $err _message;36 exit (); 37}38 39//Change the system default error handling function ("User-defined error output function", "error Type"), Set_error_handler ("My_     Error ", e_warning); $fp =fopen (" Aa.txt ", ' R '), */42 43//Error trigger, My_error3 ($error, $err _message) 46 {echo "error number:". $error;}49 function My_error4 ($error, $err _message) Cho "Big big!";     52       }53 Set_error_handler ("My_error3", e_user_warning);//54 set_error_handler ("My_error4", e_user_error);//Fatal error, do not continue Execute $age =140;56 if ($age >120) 57 {58//Call Trigger when specifying error level Trigger_error ("the number entered is too large! ", E_user_error);//trigger_error (" The number entered is too large! ", e_user_warning);//exit ();}63 echo" OK ";?>

Vi. error logs

1 <?php 2   3  //error log php.ini in Error_log configuration 4   5  function My_error5 ($error, $err _meaasge) 6  {7        $err _info= "error message:" $error. " --". $err _meaasge; 8        //echo Time (); 9//        output Current date        //     Adjust timezone: The default period is UTC and China difference 8 hours PRC or        asia/chongqing11        date_ Default_timezone_set ("PRC"),        echo Date ("Y-m-d g-i-s"),        echo "<br/>". $err _info;16        #将错误存入系统文件中18        error_log ("Time is:". Date ("Y-m-d g-i-s"). " -". $err _info." \ r \ n ", 3," Myerror.txt ");//3 parameters      }20      set_error_handler (" My_error5 ", e_user_warning);      $i =1;22      if ($i <2)      {          Trigger_error ("the number entered is too small", e_user_warning);      }26?>

Vii. Catching exceptions

1 <?php 2    3   //Handling Exception 4   #注意事项: After the exception is thrown, the code will not be executed 5   #抛出异常之后如果没用处理则会报错 6   try 7   {8       addUser (" 1a "); 9   }10   catch (Exception $e) One   {       echo "failure message:". $e->getmessage ();//getline ()       #可以继续抛出 Throw $e       #也可以顶一个顶级异常处理15       # $i =8/0  fopen ("A.txt", "R") it's hard to throw an exception.   }17   AddUser ($user)   {       if ($user = = "a")       {          echo "landing success!) ";       }24       else25 {$          throw new Exception (" Wrong user name! ");       }28   }30 to   /* #顶级异常处理32   function my_error () "I am the       top exception handling!" ". E->getmeaasge ();   }36   Set_error_handler (" My_error "); */37?>

PHP Summary Notes

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.