PHP exception handling and namespace ____php

Source: Internet
Author: User

Error_reporting: Set what PHP error to quote

Exception: Exception (unexpected problem) is the so-called error: (1) error occurred while writing (2) error at runtime

Exception handling:
Usually the wrong message is not returned to the user, but the user must be able to perform the correct action
So we need to deal with the content code that might be problematic, which is called exception handling.
Exception handling operation: Try.....catch ... code block
Try to contain the code that might be problematic, and catch to capture the exception that appears
Once a well-defined exception appears, the statement after the exception is skipped and no longer executed, and the code in the output catch block is executed
In PHP, the general is to determine whether the correct return or get the desired object or value, if not, use the Throw keyword, throw exception information

what is a namespace.

In a broad sense, namespaces are a way of encapsulating things. This abstract concept can be seen in many places. For example, in the operating system the directory is used to group related files, which play a role as namespaces for the files in the directory. For example, file foo.txt can exist in both the directory /home/greg and /home/other , but there cannot be two foo.txt files in the same directory. In addition, when accessing foo.txt files outside of the directory /home/greg , we must get /home/greg/foo.txtthe directory name and the directory delimiter before the filename. The principle applied to the domain of programming is the concept of namespaces.

In PHP, namespaces are used to address two types of problems when creating reusable code such as classes or functions when writing a class library or application:

1. User-written code conflicts with the name of a class/function/constant or third party class/function/constant inside PHP.

2. Create an alias (or short) name for a long identifier name (usually defined to mitigate the first type of problem), improving the readability of the source code.

PDO: (PHP data Object):

Preprocessing statements
$pdos 2 = $pdo->prepare ($sql 2);
Primarily used to execute DML statements
$row 2 = $pdos 2->execute (array(5));

pdo::exec-executes an SQL statement and returns the number of rows affected

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.