Namespace issues in PHP

Source: Internet
Author: User
A. php has a namespace {code ...} in the factory. php {code ...} why in factory. the createA method in php will tell me that I cannot find fooclassA in factory. php... it should go to. php. It can be used in php.5.5. php), but in step 5 .... a. php has a namespace.

namespace foo;class classA{    public function foo_test(){            echo "this is instance function";        }  }

In factory. php

namespace factory;import('a.php');class classB{    public function createA(){        return \foo\classA::foo_test();    }}

Why in factory. the createA method in php will tell me that I cannot find \ foo \ classA in factory. php... it should go to. php. It can be used in php.5.5. php), but after 5.6, it will find (factory. php)

How can I solve this problem...

Reply content:

A. php has a namespace.

namespace foo;class classA{    public function foo_test(){            echo "this is instance function";        }  }

In factory. php

namespace factory;import('a.php');class classB{    public function createA(){        return \foo\classA::foo_test();    }}

Why in factory. the createA method in php will tell me that I cannot find \ foo \ classA in factory. php... it should go to. php. It can be used in php.5.5. php), but after 5.6, it will find (factory. php)

How can I solve this problem...

PHP supports the following reference methods:

  1. Require (file_path );

  2. Require_once (file_path _;

  3. Include (file_path );

  4. Include_once (file_path );

  5. Use 'file _ path ';
    Specific differences go to google

Finally, I want to ask, what are you writing ???

Php does not seem to have the import () built-in method...
Just change it according to the @ lanffy brother...

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.