zoukankan      html  css  js  c++  java
  • PHP 学习1.3

    1.展示类的继承和静态的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>定义和调用函数</title>
    </head>

    <body>
    <?
      class Cart{
      var $items;
      function Cart(){
            $this->Say();
          }
      function addItem($product,$num){
           $this->items[$product]+=$num;
          }
      function reomveItem($product,$num){
            if($this->items[$product]>$num){
                 $this->items[$product]-=$num;
                 return true;
                }elseif($this->items[$product]==$num){
                    unset($this->items[$product]);
                    return true;
                }
              else{
                return false;
                }
          }
       function  ShowCart(){
             foreach($this->items as $k=>$v){
           echo "<br/> ".$k."=".$v;
          }
           }
       function Say(){
             echo "<br/> I'm Cart";
           }
       static    function  SayHello(){
               echo "<br/> Hello World!";
               }
          }
      class AutoCart extends Cart
      {
        function AutoCart(){
             $this->addItem("product1",1);
             $this->Say();
             }
        function ConstructCart($p="11",$n=2){
           $this->addItem($p,$n);
             }
        function Say(){
             echo "<br/> I'm AutoCart";
           }
      }
    Cart::SayHello();
    $cart = new AutoCart();
    $cart->ShowCart();
    $cart2=new Cart();
    $cart2->addItem("12",2);
    $cart2->ShowCart();

    ?>
    </body>
    </html>

  • 相关阅读:
    跳板机操作
    常用进制之间的转换
    vim加脚本注释和文本加密
    LAMP框架
    wiki团队协作软件Confluence
    NFS网络文件系统
    ORACLE-12C-RAC INSTALL
    通过DB_LINK按照分区表抽取数据
    Oracle Rac crs无法启动
    删除undotbs后,数据库无法启动
  • 原文地址:https://www.cnblogs.com/linsu/p/3473404.html
Copyright © 2011-2022 走看看