How to use php built-in classes in namespace

Source: Internet
Author: User
How do I use php built-in classes in the namespace? Hello, php beginners. if you have any questions, please refer to the code in a php file. Contains two namespaces, test2 and test4. in test2, the Exception class throws an error and is detected in test4 space, but how can I use php built-in classes in test2 if I cannot find them in the namespace?
Hello, I am a beginner in php. if you have any questions, please advise:
Here is the code in a php file. Contains two namespaces, test2 and test4. in test2, the Exception class throws an error.
The error is detected in test4 space, but the Exception class cannot be found in test2 during runtime. Therefore, the Exception class in the red part is
The root space is specified as \, But Exception $ e error is prompted in catch statement in test4.
How can I modify it? thank you.
Namespace test2 {
Class {
Private $ file_id;

Public function file_open ($ path_file_name ){
$ This-> file_id = @ fopen ($ path_file_name, 'r ');
If ($ this-> file_id = false) {throw new \ Exception ("path_file_name isnot EXIST ");
Echo (nl2br (sprintf ("file open failed \ n ")));}
}
}
}

Namespace test4 {
Use test2;
Try {
$ Obj_A = new test2 \ ();
$ Path_name = "/home/zhiys/php/111.php ";
$ Obj_A-> file_open ($ path_name );
} Catch (Exception $ e ){...}

}

------ Solution --------------------
Catch (\ Exception $ e)

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.