PHP Object-oriented abstract class interface constant learning

Source: Internet
Author: User
Tags abstract array definition bool insert interface mysql table name

 

Use and definition of PHP abstract class   <?php   abstract class A {   public $name;    function Fun () {&nbsp ;   Echo $this->name;   &NBSP}   abstract function cc ($n, $nn =3); &NBSP}  class B extends a{   function cc ($m, $mm =7) {   echo "AAA";    }  } &nbsp ; $b = new B;  ?> PHP Object-oriented, interface definition using <?php       interface in_a{    const na=7; const NB=9; &nb Sp  function Fun ();    function fun2 ();   &nbsp        interface in_b{    function fun3 ();    }    class b{    Function cc () {}        class A extends B implements in_a,in_b{    &NBSP ; function fun () {} function fun2 () {} function Fun3 () {}                 $p =new A;    ?>   Two examples:   abstract class Example:   <?php   abstract class mysql{    PUBlic $host//host address public $user;//user name public $passwd; Public $dbname; Public $charset;   function __construct ($h, $u, $p, $d, $c) {  $this->host= $h;   $this->user= $u;   $this-> Passwd= $p;   $this->dbname= $d;   $this->charset= $c;   $this->conn (); }   Function Conn () {@mysql_connect ($this->host, $this->user, $this->passwd) or Die ("MySQL connection failed") @mysql_ select_db ($this->dbname) or Die ("database connection failed"); $this->q ("Set Names '") $this->charset. "'"); }   function Q ($n) { return mysql_query ($n);}   function ID () { return mysql_insert_id ();}   FU Nction f ($n, $st =1) { switch ($st) { case 1:   $rs =mysql_fetch_array ($n);  break;  case 2:   $rs =mysql_fetch_row ($n);  break; return $rs; &NBSP}//========================/** * Description: Into Insert Database method * Parameter: $TB table name, $val for insert value, $st debug mode, 1 Debug 0 Debugging * return: int   *   & Nbsp;abstract function into ($TB, $val, $st =0);        /** * Description: Sel_oNCE query * Parameters: $TB table name, $WH conditions default 1, $ar set the field, $ty query type, default subscript and key name, $st debug state, default to 0, 1 Debug 0 Debug * return: Array [] / abstra CT function sel_once ($TB, $wh =1, $ar = "*", $ty =1, $st =0);      /** * Description: Sel_all query * Parameters: $TB table name, $WH conditions default 1, $ar set the field, $ty query type, default subscript and key name, $st debug state, default for 0, 1 Debug 0 Debug * return: Array [two-dimensional Array] /   abstract function Sel_all ($TB, $wh =1, $ar = "*", $ty =1, $st =0);      /** * Description: Update updates the database method * Parameters: $TB table name, $val update content $WH conditions [1 limit 1], $st debug mode default 0,1 debug 0 debugging * return: int   * * &NB Sp  abstract function Update ($TB, $val, $wh = "1 limit 1", $st =0);          /** * Description: Del Delete database method * Parameter: $TB table name, $WH condition [1 limit 1], $st debug mode default 0,1 debug 0 debugging * return: int  /& nbsp  abstract function del ($TB, $WH = "1 limit 1", $st =0); Learning examples for             { ?>   interface:   <?php   interface in_a{&nbsp ;  /**     Description: Login method Login     Parameters: $user username, $passwd password     return: BOOL [generate cookie]    */& NBsP  function Login ($user, $passwd); &NBSP}     Interface in_b{   /**     Description: Checklogin Check login     parameters: $n User default permissions 1 can specify different pages for User different permissions     return: bool    */  function checklogin ($n =1); &NBSP}     Interface in_c{   /**     Description: Checklogintime Check login timeout     Parameters: $ N is timeout default 3,600 sec     return: bool    */  function checklogintime ($n =3600); &NBSP}    //topic 1 Requirements: Landing page requires the use of In_a In_b interface  //Topic 2 requirements: After landing page requirements to use In_b In_c interface    ?>

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.