• 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:>
  • 相关阅读:
    《Java程序设计》第七次学习总结
    《Java程序设计》第六次学习总结
    实验二:Java面向对象程序设计
    《信息安全系统设计基础》第二次学习总结
    《信息安全系统设计基础+Linux 内核分析》第一次学习总结
    《Java程序设计》第五次学习总结
    《Java程序设计》第四次学习总结
    《Java程序设计》第三次学习总结
    next_permutation 函数
    POJ 3268 (dijkstra算法)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6761864.html
Copyright © 2020-2023  润新知