<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # 調試應用程序 ![](https://docs.phalconphp.com/images/content/xdebug-1.jpg) PHP提供了使用通知,警告,錯誤和異常來調試應用程序的工具。[Exception類](http://www.php.net/manual/en/language.exceptions.php)提供有關錯誤發生位置的信息,如文件,行,消息,數字代碼,回溯等。像Phalcon這樣的OOP框架主要使用此類來封裝此功能,并將信息提供給開發人員或用戶。 盡管用C語言編寫,但Phalcon在PHP用戶區中執行方法,提供了用PHP編寫的任何其他應用程序或框架的調試功能。 ## 捕捉異常 在整個Phalcon文檔的教程和示例中,有一個共同的元素是捕獲異常。這是一個`try/catch`塊: ```php <?php try { // ... Some Phalcon/PHP code } catch (\Exception $e) { } ``` 塊中拋出的任何異常都會在變量`$e`中捕獲。`Phalcon\Exception` 擴展了PHP [Exception類](http://www.php.net/manual/en/language.exceptions.php),用于了解異常是來自Phalcon還是PHP本身。 PHP生成的所有異常都基于[Exception類](http://www.php.net/manual/en/language.exceptions.php),并且至少包含以下元素: ```php <?php class Exception { /* Properties */ protected string $message; protected int $code; protected string $file; protected int $line; /* Methods */ public __construct ([ string $message = '' [, int $code = 0 [, Exception $previous = NULL ]]]) final public string getMessage ( void ) final public Exception getPrevious ( void ) final public mixed getCode ( void ) final public string getFile ( void ) final public int getLine ( void ) final public array getTrace ( void ) final public string getTraceAsString ( void ) public string __toString ( void ) final private void __clone ( void ) } ``` 從 `Phalcon\Exception` 中檢索信息與PHP的 [Exception類](http://www.php.net/manual/en/language.exceptions.php)相同: ```php <?php try { // ... App code ... } catch (\Exception $e) { echo get_class($e), ': ', $e->getMessage(), '\n'; echo ' File=', $e->getFile(), '\n'; echo ' Line=', $e->getLine(), '\n'; echo $e->getTraceAsString(); } ``` 因此,很容易找到應用程序代碼的哪個文件和行生成異常,以及生成異常所涉及的組件: ```html PDOException: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO) File=/Applications/MAMP/htdocs/invo/public/index.php Line=74 #0 [internal function]: PDO->__construct('mysql:host=loca...', 'root', '', Array) #1 [internal function]: Phalcon\Db\Adapter\Pdo->connect(Array) #2 /Applications/MAMP/htdocs/invo/public/index.php(74): Phalcon\Db\Adapter\Pdo->__construct(Array) #3 [internal function]: {closure}() #4 [internal function]: call_user_func_array(Object(Closure), Array) #5 [internal function]: Phalcon\Di->_factory(Object(Closure), Array) #6 [internal function]: Phalcon\Di->get('db', Array) #7 [internal function]: Phalcon\Di->getShared('db') #8 [internal function]: Phalcon\Mvc\Model->getConnection() #9 [internal function]: Phalcon\Mvc\Model::_getOrCreateResultset('Users', Array, true) #10 /Applications/MAMP/htdocs/invo/app/controllers/SessionController.php(83): Phalcon\Mvc\Model::findFirst('email='demo@pha...') #11 [internal function]: SessionController->startAction() #12 [internal function]: call_user_func_array(Array, Array) #13 [internal function]: Phalcon\Mvc\Dispatcher->dispatch() #14 /Applications/MAMP/htdocs/invo/public/index.php(114): Phalcon\Mvc\Application->handle() #15 {main} ``` 從上面的輸出可以看出,Phalcon的類和方法就像任何其他組件一樣顯示,甚至顯示每次調用中調用的參數。如果需要,方法[Exception::getTrace](http://www.php.net/manual/en/exception.gettrace.php) 提供其他信息。 ## 調試組件 Phalcon提供了一個調試組件,允許開發人員輕松找到使用框架創建的應用程序中產生的錯誤。 以下截屏視頻介紹了它的工作原理: <div align='center'> <iframe src='//player.vimeo.com/video/68893840' width='500' height='313' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> </div> 要啟用它,請將以下內容添加到啟動程序中: ```php <?php $debug = new \Phalcon\Debug(); $debug->listen(); ``` 必須刪除或禁用任何 `Try/Catch` 塊才能使此組件正常工作。 ## 反射與內省 Phalcon類的任何實例都提供與PHP普通實例完全相同的行為。可以使用[Reflection API](http://php.net/manual/en/book.reflection.php)或只是打印任何對象來顯示其內部狀態如何: ```php <?php $router = new Phalcon\Mvc\Router(); print_r($router); ``` 很容易知道任何對象的內部狀態。上面的示例打印以下內容: ```html Phalcon\Mvc\Router Object ( [_dependencyInjector:protected] => [_module:protected] => [_controller:protected] => [_action:protected] => [_params:protected] => Array ( ) [_routes:protected] => Array ( [0] => Phalcon\Mvc\Router\Route Object ( [_pattern:protected] => #^/([a-zA-Z0-9\_]+)[/]{0,1}$# [_compiledPattern:protected] => #^/([a-zA-Z0-9\_]+)[/]{0,1}$# [_paths:protected] => Array ( [controller] => 1 ) [_methods:protected] => [_id:protected] => 0 [_name:protected] => ) [1] => Phalcon\Mvc\Router\Route Object ( [_pattern:protected] => #^/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)(/.*)*$# [_compiledPattern:protected] => #^/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)(/.*)*$# [_paths:protected] => Array ( [controller] => 1 [action] => 2 [params] => 3 ) [_methods:protected] => [_id:protected] => 1 [_name:protected] => ) ) [_matchedRoute:protected] => [_matches:protected] => [_wasMatched:protected] => [_defaultModule:protected] => [_defaultController:protected] => [_defaultAction:protected] => [_defaultParams:protected] => Array ( ) ) ``` ## 使用XDebug [XDebug](http://xdebug.org) 是一個很棒的工具,可以補充PHP應用程序的調試。它也是PHP的C擴展,您可以將它與Phalcon一起使用而無需額外的配置或副作用。 以下截屏視頻顯示了與Phalcon的Xdebug會話: <div align='center'> <iframe src='//player.vimeo.com/video/69867342' width='500' height='313' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> </div> 安裝xdebug后,您可以使用其API獲取有關異常和消息的更詳細信息。 >[warning] 我們強烈建議使用最新版本的XDebug,以便與Phalcon更好地兼容。 以下示例實現[xdebug_print_function_stack](http://xdebug.org/docs/stack_trace)以停止執行并生成回溯: ```php <?php use Phalcon\Mvc\Controller; class SignupController extends Controller { public function indexAction() { } public function registerAction() { // Request variables from HTML form $name = $this->request->getPost('name', 'string'); $email = $this->request->getPost('email', 'email'); // Stop execution and show a backtrace return xdebug_print_function_stack('stop here!'); $user = new Users(); $user->name = $name; $user->email = $email; // Store and check for errors $user->save(); } } ``` 在這種情況下,Xdebug還會向我們展示本地范圍內的變量,以及回溯: ```html Xdebug: stop here! in /Applications/MAMP/htdocs/tutorial/app/controllers/SignupController.php on line 19 Call Stack: 0.0383 654600 1. {main}() /Applications/MAMP/htdocs/tutorial/public/index.php:0 0.0392 663864 2. Phalcon\Mvc\Application->handle() /Applications/MAMP/htdocs/tutorial/public/index.php:37 0.0418 738848 3. SignupController->registerAction() /Applications/MAMP/htdocs/tutorial/public/index.php:0 0.0419 740144 4. xdebug_print_function_stack() /Applications/MAMP/htdocs/tutorial/app/controllers/SignupController.php:19 ``` Xdebug提供了幾種使用Phalcon獲取有關應用程序執行情況的調試和跟蹤信息的方法。您可以查看[XDebug](http://xdebug.org/docs)文檔以獲取更多信息。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看