PHP Namespace Base Usage

Source: Internet
Author: User

file1.php:

namespace Foobarsubnamespace;

Const FOO = 1;
function foo () {}
Class foo{
static function Staticmethod () {}
}
?>

file2.php:

namespace FooBar;
Include ' file1.php ';

Const FOO = 2;
function foo () {}
Class foo{
static function Staticmethod () {}
}

Unqualified name

Foo (); resolves to foo\bar\foo resolves to function foo\bar\foo
Foo::staticmethod (); A static method staticmethod that resolves to a class foo\bar\foo. resolves to class Foo\bar\foo, method Staticmethod
Echo FOO; resolves to constant foo\bar\foo

Qualified name

Subnamespace\foo (); Parse to function Foo\bar\subnamespace\foo
Subnamespace\foo::staticmethod (); resolves to class Foo\bar\subnamespace\foo, and methods of classes Staticmethod
Echo Subnamespace\foo; Resolve to constant Foo\bar\subnamespace\foo

Fully qualified name

\foo\bar\foo (); Parse to function Foo\bar\foo
\foo\bar\foo::staticmethod (); resolves to class Foo\bar\foo, and methods of classes Staticmethod
Echo \foo\bar\foo; Resolve to constant Foo\bar\foo
?>

Reply content:

file1.php:

namespace Foobarsubnamespace;

Const FOO = 1;
function foo () {}
Class foo{
static function Staticmethod () {}
}
?>

file2.php:

namespace FooBar;
Include ' file1.php ';

Const FOO = 2;
function foo () {}
Class foo{
static function Staticmethod () {}
}

Unqualified name

Foo (); resolves to foo\bar\foo resolves to function foo\bar\foo
Foo::staticmethod (); A static method staticmethod that resolves to a class foo\bar\foo. resolves to class Foo\bar\foo, method Staticmethod
Echo FOO; resolves to constant foo\bar\foo

Qualified name

Subnamespace\foo (); Parse to function Foo\bar\subnamespace\foo
Subnamespace\foo::staticmethod (); resolves to class Foo\bar\subnamespace\foo, and methods of classes Staticmethod
Echo Subnamespace\foo; Resolve to constant Foo\bar\subnamespace\foo

Fully qualified name

\foo\bar\foo (); Parse to function Foo\bar\foo
\foo\bar\foo::staticmethod (); resolves to class Foo\bar\foo, and methods of classes Staticmethod
Echo \foo\bar\foo; Resolve to constant Foo\bar\foo
?>

  • 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.