zoukankan      html  css  js  c++  java
  • debug_backtrace final catch

    <?php
    function backtrace_str(){
            $str = '';
        $w = 0;
        $backtrace = debug_backtrace();
            foreach($backtrace as $arr){
            $str .= $w."
    ";
            $w++;
                    foreach($arr as $key=>$val){
                    $str .=$key.'=>'.$val."
    ";
                    }
            }
            return $str;
    }

     w

    http://php.net/manual/en/language.oop5.final.php

    PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.

    http://php.net/manual/zh/language.oop5.final.php

    PHP 5 新增了一个 final 关键字。如果父类中的方法被声明为 final,则子类无法覆盖该方法。如果一个类被声明为 final,则不能被继承。

    http://php.net/manual/en/language.exceptions.extending.php

    w

    <?php
    class Exception
    {
        protected $message = 'Unknown exception';   // exception message
        private   $string;                          // __toString cache
        protected $code = 0;                        // user defined exception code
        protected $file;                            // source filename of exception
        protected $line;                            // source line of exception
        private   $trace;                           // backtrace
        private   $previous;                        // previous exception if nested exception
    
        public function __construct($message = null, $code = 0, Exception $previous = null);
    
        final private function __clone();           // Inhibits cloning of exceptions.
    
        final public  function getMessage();        // message of exception
        final public  function getCode();           // code of exception
        final public  function getFile();           // source filename
        final public  function getLine();           // source line
        final public  function getTrace();          // an array of the backtrace()
        final public  function getPrevious();       // previous exception
        final public  function getTraceAsString();  // formatted string of trace
    
        // Overrideable
        public function __toString();               // formatted string for display
    }

    w

    <?php
    function inverse($x)
    {
        if (!$x) {
            throw new Exception('Division by zero.');
        }
        return 1 / $x;
    }
    
    try {
        echo inverse(5) . "
    ";
        echo inverse(0) . "
    ";
    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "
    ";
    }
    
    function w($w)
    {
        try {
            echo inverse($w) . "
    ";
            return 'w0';
        } catch (Exception $e) {
            echo 'Caught exception: ', $e->getMessage(), "
    ";
        }
        return 'w1';
    }
    
    $w = w(5);
    print_r($w);
    $w = w(0);
    print_r($w);
    C:>php D:cmdamzapiamzapitest_comMarketplaceWebServiceOrdersSampleswd_learn.php
    0.2
    Caught exception: Division by zero.
    0.2
    w0Caught exception: Division by zero.
    w1
    C:>
  • 相关阅读:
    【求助】Oracle 新手困惑,System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
    什么是APS高级计划排程(高级计划排产)一
    【求助】Html弄的比较少,问一个弱弱的问题,为什么下面代码在IE中tr之间有空白行,而在Firefox中没有空白
    使用Jmeter测试快速入门
    Jmeter数据库压测(Windows下进行压测)
    Charles安装真机证书
    Jmeter组件参数化
    Jmeter脚本录制(App)
    Jmeter的介绍
    Fiddler的使用
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6761864.html
Copyright © 2011-2022 走看看