如何建立PHP偵錯環境(以XAMPP與VS Code為例)

//宣告方式
const //constant(常數),宣告後,值不能改變
var //variable(變數),宣告後,值可以變更
let //variable(變數),宣告後,值可以變更(ES6後,建議使用)

//基本型別:number、string、boolean、null、undefined
//物件型別:object、function

typeof 3.14159 //number
typeof “flystudiox” //string
typeof true //boolean
typeof {} //object
typeof [] //object
typeof null //object
typeof undefined //undefined
typeof alert //function
typeof NaN //number</code></pre>

下載並安裝 XAMPP

  • phpinfo()

下載並安裝 Visual Studio Code

  • 延伸模組
    • PHP Debug
  • 設定 (注意JSON特殊字元)
    {
        "php.validate.executablePath": "C:/xampp/php/php.exe",
        "php.debug.executablePath": "C:/xampp/php/php.exe"
    }

    下載 XDebug

    • PHP Version
    • 8.1.6 = PHP 8.1
    • Architecture
    • x64 = 64 bit
    • x86 = 32 bit
    • Thread Safety
    • enabled
    • disabled

設定 XDebug

  • C:\xampp\php\php.ini

    zend_extension="C:\xampp\php\ext\php_xdebug-3.1.4-8.1-vs16-x86_64.dll"
    
    xdebug.mode = debug
    xdebug.start_with_request = yes
    • C:\xampp\htdocs
    • menu.php

Leave a Reply

Your email address will not be published. Required fields are marked *