PHP错误处理
PHP错误处理
PHP错误处理
错误的分类:
语法错误:程序没法运行,直接提示语法错误
运行时错误:只有程序运行到某行,或在某此特定的情形下运行才会发生的错误。
逻辑错误:程序从头到尾运行都没有发生(并提示)错误,但程序运行计算的结果是错误的。
程序员主要面对的和要处理的错误,就是运行时错误。
错误的分级:
在php中,将各种错误,分门别类,依据不同的严重程序和产生的来源(机制),将各种错误分为大约十几个级别。
每个级别的错误,都对应一个内部的名称--系统常量!
系统错误:
E_ERROR 系统严重错误 (一发生,程序立即停止执行。该错误一般希望马上解决)
E_WARNING 系统警告 (一发生,提示错误,并继续执行。通常该错误希望能够在“下一工作日”去处理掉)
E_PARSE 语法错误 (一发生,提示错误,而且代码完全不会运行--在运行之前先检查语法。)
E_NOTICE 系统提示 (一发生,提示错误,并继续执行。发个邮件通知下,自己安排时间有空去解决。)
它们的本质是什么呢?
echo "
E_ERROR = ".E_ERROR;
echo "
E_WARNING = ".E_WARNING;
echo "
E_PARSE = ".E_PARSE;
echo "
E_NOTICE = ".E_NOTICE;
输出的结果分别为:
E_ERROR = 1
E_WARNING = 2
E_PARSE = 4
E_NOTICE = 8
可见它们只是一个系统内部的常量(整数常量);实际上,这些常量(代号)是供我们对该类错误进行“控制”的标示符而已。
用户自定义错误:
只有三个:
E_USER_ERROR
E_USER_WARNING
E_USER_NOTICE
我们可以在程序中,自己创建(生成)错误 -- 是为了针对某些数据的不合理情形而创建的错误
比如:让用户填写年龄,填18是OK,但填写188,则就是不合理 -- 从数字角度本身是没有问题的
其它错误:
E_ALL 代表所有错误 -- 表示它可以“包括”所有错误。
E_STRICT 代表“严格性”语法检查错误 -- 某种语法是可以执行的,但在当前的php版本是不欢迎使用。

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











PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

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 is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.
