PHP 程序员的调试技术小结_PHP
程序员
本文介绍调试 PHP 应用程序的各种方法,包括在 Apache and PHP 中打开错误报告,以及通过在一个简单的 PHP 脚本中放置策略性的 print 语句,找到更困难的 bug 的源头。还会介绍用于 Eclipse 的 PHPEclipse 插件,这是一个灵活的开发环境,具有实时语法解析能力,还会介绍 PHPEclipse 的 DBG 调试器扩展。
简介
有许多 PHP 调试技术可以在编码的时候节约大量时间。一个有效却很基本的调试技术就是打开错误报告。另一个略微高级一点的技术包括使用 print 语句,通过显示在屏幕上实际出现的内容,有助于精确地找出更难发现的 bug。PHPEclipse 是一个 Eclipse 插件,能够强调常见的语法错误,可以与调试器结合起来用于设置断点。
设置
要学习本文描述的概念,需要 PHP、Web 服务器和 Eclipse。调试器扩展支持的 PHP 版本是 V5.0.3。
我们需要一个 Web 服务器来解析用 PHP 创建的页面并把它们显示到浏览器。本文中使用的是 Apache2。但是,任何 Web 服务器都可以满足要求。
要利用本文中介绍的一些调试技术,需要安装 Eclipse V3.1.1 和插件 PHPEclipse V1.1.8。由于 Eclipse 要求 Java™ 技术,所以还要下载它。
还需要 PHP 的调试器扩展模块。安装它略有些麻烦。请仔细跟随安装调试器扩展的操作说明。现在,先在 php.ini 文件中注释掉那些要求装入和配置 PHP 扩展的行。在需要使用调试器的时候,再取消注释。
请参阅 参考资料 获得下载信息。现在介绍出错消息。
出错消息
出错消息是作为开发人员的第一道防线。谁都不想在一台没有配置成显示出错消息的服务器上用 PHP 开发代码。但是,请记住,当代码调试完成,准备运行的时候,应当确保关闭了错误报告,因为不希望站点的访问者看到出错消息,因为这会给他们提供足够的信息来利用站点的弱点并黑掉站点。
也可以用出错消息为自己服务,因为它们会显示抛出或生成错误的正确代码行。这样,调试就变成在浏览器上查看生成的错误所显示的行号,并在代码中检查这一行。稍后,将会看到 PHPEclipse 插件通过即时地给语法错误加下划线并在保存文件时用红色 “x” 标注语法错误,可在开发和调试过程中提供极大的帮助。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
