Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP Manual > Namespace definition





ลองใช้ค้นหาข้อมูล


   
Bookmark.

Namespace definition

The namespace is declared using namespace keyword, which should be at the very beginning of the file. Example:

Example #1 Defining namespace

<?php
    namespace MyProject
::DB;
    
    const 
CONNECT_OK 1;

    class 
Connection /* ... */ }
    
    function 
connect() { /* ... */  }
    
?>
Same namespace name can be used in multiple files.

Namespace can contain class, constant and function definitions, but no free code.

Namespace definition does the following:

  • Inside namespace, all class, function and constant names in definitions are automatically prefixed with namespace name. The class name is always the full name, i.e. in the example above the class is called MyProject::DB::Connection.
  • Constant definitions create constant which is composed of namespace name and constant name. Like class constants, namespace constant can only contains static values.
  • Unqualified class name (i.e., name not containing ::) is resolved at runtime following this procedure:

    1. Class is looked up inside the current namespace (i.e. prefixing the name with the current namespace name) without attempting to autoload.
    2. Class is looked up inside the global namespace without attempting to autoload.
    3. Autoloading for name in current namespace is attempted.
    4. If previous failed, lookup fails.

  • Unqualified function name (i.e., name not containing ::) is looked up at runtime first in the current namespace and then in the global space.

  • Unqualified constant names are looked up first at current namespace and then among globally defined constants.

See also the full name resolution rules.



ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่