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:>
  • 相关阅读:
    Codeforces 992C(数学)
    Codeforces 990C (思维)
    Codeforces 989C (构造)
    POJ 1511 Invitation Cards(链式前向星,dij,反向建边)
    Codeforces 1335E2 Three Blocks Palindrome (hard version)(暴力)
    POJ 3273 Monthly Expense(二分)
    POJ 2566 Bound Found(尺取前缀和)
    POJ 1321 棋盘问题(dfs)
    HDU 1506 Largest Rectangle in a Histogram(单调栈)
    POJ 2823 Sliding Window(单调队列)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6761864.html
Copyright © 2011-2022 走看看