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 > Using namespaces





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


   
Bookmark.

Using namespaces

Every class and function in a namespace can be referred to by the full name - e.g. MyProject::DB::Connection or MyProject::DB::connect - at any time.

Example #1 Using namespaced name

<?php
    
require 'MyProject/Db/Connection.php';
    
$x = new MyProject::DB::Connection;
    
MyProject::DB::connect();
?>

Namespaces can be imported into current context (global or namespace) using the use operator. The syntax for the operator is:

<?php
/* ... */
use Some::Name as Othername;

// The simplified form of use:
use Foo::Bar;
// which is the same as :
use Foo::Bar as Bar;
?>
The imported name works as follows: every time that the compiler encounters the local name Othername (as stand-alone name or as prefix to the longer name separated by ::) the imported name Some::Name is substituted instead.

use can be used only in global scope, not inside function or class. Imported names have effect from the point of import to the end of the current file. It is recommended to put imports at the beginning of the file to avoid confusion.

Example #2 Importing and accessing namespace

<?php
    
require 'MyProject/Db/Connection.php';
    use 
MyProject::DB;
    use 
MyProject::DB::Connection as DbConnection;
    
    
$x = new MyProject::DB::Connection();
    
$y = new DB::connection();
    
$z = new DbConnection();
    
DB::connect();
?>

Note: The import operation is compile-time only, all local names are converted to their full equivalents by the compiler. Note that it won't translate names in strings, so callbacks can't rely on import 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 อัตราราคา คลิกที่นี่