1. 内置的API输出
echo/print
echo的速度较快, 且可以输出逗号分隔的多个变量
printf/sprintf/vprintf
用户格式化的一些输出或得到返回值
print_r/var_dump(var_export)/debug_zval_dump/debug_print_backtrace
输出数组,var_export输出的数组可以直接复制,debug_zval_dump包含引用次数,debug_print_backtrace可以让我们查看整个程序的调用栈,用来查看瞬间函数调用栈,方便在出错时查看执行上下文,不需要参数,直接调用
2. 错误选择控制和日志记录调试
Php.ini 配置中,跟错误相关的选项主要:error_reporting、display_errors、log_errors、error_log 等几个,这些选项在一般语法级别的调试是很有帮助的。
display_errors 是设定是否在PHP脚本执行输出的时候输出错误信息,一般在线下开发调试环境,为了便于调试,会打开错误显示选项,在线上为了不泄露敏感信息,一般会吧 display_errors 设置为Off。如果线上报错了,我们如何查看到错误?那么就需要 log_errors 选项了。这个选项是设定是否记录错误日志,以及error_log指明日志的路径。
错误抛出和处理,主要是说我们在程序中能够自己触发错误,或者自己截获处理错误,类似 throw catch机制。
trigger_error, set_error_handler, set_exception_handle这三个api就是处理错误抛出和处理内置函数。
trigger_error可以触发一个错误,触发基本跟上文的error_reporting设定的级别一直,主要是能够触发E_USER_ERROR,
E_USER_WARNING, E_USER_NOTICE三种级别的错误,如果不做处理,程序执行就会报错,错误类似于error_reporting,但是页面不能显示,但是cli执行可以显示。
set_error_handler 说我们发生了错误的时候,用什么处理函数来处理,一般这个都是用来针对 trigger_error 之后来进行错误处理的,两个函数结合,我们可以构建一个简单有效的错误识别和记录的功能。会传递参数errno errstr errfile errline
Set_exception_handler 跟 set_error_handler 类似,不过 Set_exception_handler 是用来处理出现未捕获的异常之后需要调用的处理方法。
日志记录除了PHP解析级别的错误,更多是我们程序在执行过程中的一些错误,比如 文件资源打开错误(文件不存在、没有权限、文件格式不正确)、远程服务资源访问失败(网络不通、协议不正确、用户名密码错误)等等,要知道,任何你认为不会出错的地方都可能隐藏着错误,所以务必多多的输出Log。
可以写一个简单的日志记录类,其实就是记到不同的文件中。
写log大抵都是几个常用的文件操作API,比如 fopen/fwrite,或者是一步到位的 file_put_contents。另外,PHP为了便于写日志,还提供了一个专门的接口:error_log
3. 浏览器调试
如果Web前端调试来说,Firebug是不可或缺好的调试工具,它能够监控网络、监测css、js错误,查看DOM节点,FirePHP是一个附加在 firebug 上面的插件,用来调试PHP,操作过程很简单。在PHP端使用FirePHP提供的PHP日志记录类库来输出调试信息, 在浏览器端使用 Firebug + FirePHP 来接收查看输出的调试信息,这些调试信息会直接附加在返回的HTTP头信息里,这些信息不会被浏览器直接显示,只会在firephp 获取显示,有效的达到了调试和页面显示都不冲突的问题。(必须使用firefox浏览器)。要在服务器端部署FirePHPCore文件,然后就可以调用提供的方法,在header中输出一些变量,可以有各种group,table和展现效果(warn info error)。可以查看trac, exception。参考http://www.firephp.org/HQ/Use.htm了解更多信息
4. IDE调试
zend支持本地调试,设置断点,步步跟踪,同时可以安装zend Debugger 进行远程调试。
ZendDebugger 是一个Zend扩展,通过跟IDE进行通信来达到设置断点和调试的目的。基本工作原理是:IDE 会设置监听一个调试端口,在调试的时候设置一个远程Web服务器地址,调试的时候触发URL信息,通知调试器 ZendDebugger 来访问 IDE 开放的调试端口,双方连接上以后,开始互相依靠传递消息来进行调试工作,知道调试完成,网路连接断开。但对基于ZendFramework的程序似乎不太管用,zf内嵌了zend_debug,或许可以看一下。
5. APD(Advanced PHP Debugger)
......
6. 使用Xhprof 进行性能分析
.....

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment