zoukankan      html  css  js  c++  java
  • PHP抽象接口析构方法

    /*class Ren
    {
    public static $color;
    static function Show()
    {
    Ren::$color;//用类名不仅可以调用自己的,还可以调用其他类的Car::$name
    self::$color;//用self只能调用该类
    }
    }
    class Car
    {
    public static $name;
    }*/
    //抽象类 关键词abstract
    /*abstract class DongWu
    {
    public $dong;
    public $jiao;
    function Chi()
    {
    }
    function Shui()
    {
    }
    }*/
    //接口:极度抽象的类 继承自接口 必须实现接口里的方法,重写
    //接口关键字interface 接口里面的方法没有函数体 实现接口使用的关键字 implement,不用extends 实现接口的子类必须实现接口的每个方法
    /*interface DongWu//使用interface关键字就不加class
    {}
    class Ren extends DongWu
    {
    }
    $r=new Ren();
    var_dump($r);*/
    //$d=new DongWu();
    /*interface USB
    {
    function Read();
    function Write();
    }
    //鼠标
    class Mouse implements USB
    {
    function Read()
    {
    echo"插入鼠标";
    }
    function Write()
    {
    echo"通电鼠标";
    }
    }
    //键盘
    class JianPan implements USB
    {
    function Read()
    {
    echo"插入键盘";
    }
    function Write()
    {
    echo"通电键盘";
    }
    }
    $m=new Mouse();
    $m->Read();
    $m->Write();*/
    class Ren
    {
    public $name="张三";
    public $sex;
    public $age;
    function Run()
    {
    }
    function show()
    {
    echo"name代表姓名,sex代表性别";
    }
    //析构方法 关键字__destruct 在对象销毁之前,将内存释放,连接关闭等
    function __destruct()
    {
    echo"销毁了";
    }
    //在输出对象的时候调用,必须有一个返回值
    function __tostring()
    {
    //return"name代表姓名,sex代表性别"
    return $this->name;
    }
    }
    //写法特殊 __destruct
    //执行时间特殊 在对象销毁的时候执行
    /*$r=new Ren();
    $r->name="张三";
    var_dump($r);*/
    $r=new Ren();
    //$r->show();
    echo $r;//直接输出对象 __tostring()把对象变成字符串的方法
    //小知识点
    $a=10;
    $b=20;
    $c=25;
    unset($b);
    /*if(isset($b))
    {
    $sum=$a+$b;
    echo $sum;
    echo "<br>";
    echo $a*$sum;
    }*/
    if(!isset($b))
    {
    /*echo"变量b不存在";
    exit();//退出程序*/
    die("变量b不存在");//输出错误信息并退出程序
    }
    $sum=$a+$b;
    echo $sum;
    echo "<br>";
    echo $a*$sum;
    $attr=array(1,2,3,4);
    $a = "hello";
    var_dump($attr);//数据和类型
    print_r($attr);//数据
    echo "hhh","hh";//可以输出多个字符串 中间用逗号
    print "rr"; //只能输出一个字符串

  • 相关阅读:
    SharePoint 2013 APP 开发示例 (六)服务端跨域访问 Web Service (REST API)
    麦咖啡导致电脑不能上网
    SharePoint 2013 Central Admin 不能打开
    SharePoint 2013 APP 开发示例 (五)跨域访问 Web Service (REST API)
    SharePoint 2013 APP 开发示例 系列
    synthesize(合成) keyword in IOS
    Git Cmd
    简单的正则匹配
    Dropbox
    SQL Server Replication
  • 原文地址:https://www.cnblogs.com/hamilton/p/5592173.html
Copyright © 2011-2022 走看看