One particularly useful new addition to PHP 5.3.0 is namespaces. Namespaces allow developers to sandbox their code, outside of the global namespace, to avoid class name conflicts and help organize their code better.We will make use of namespaces in almost all of the classes we write, and they are not particularly tricky to use. Consider the example presented below: Example : namespace Framework { class Hello { public function world() { echo "Hello world!"; } } } namespace Foo { // allows us to refer to the Hello class // without specifying its namespace each time use Framework\Hello as Hello; class Bar { function construct() { // here we can refer to Framework\Hello as simply Hello // due to the preceding "use" statement $hello = new Hello(); $hello->world(); } } } namespace { $hello = new Framework\Hello(); $hello->world(); //… prints "Hello world!" $foo = new Foo\Bar(); $foo->bar(); //… prints "Hello world!" } As mentioned before, namespaces help to remove classes from the global namespace. The namespace itself remains within the global namespace, so it must remain unique; however, it can contain any number of classes, which can reuse class names that are in the global namespace, or within other namespaces.
Wednesday, October 21, 2015
What is Namespace in PHP?
ព័ត៌មានដែលទាក់ទង
- 1. Explain the principles of networking2. Describe types of networks3. Describe basic net
- What is a datacenter?A datacenter is the primary container of inventory objects such as h
- Normal 0 false false false EN-US X-NONE KHM
- How to Enable or Disable Auto Apps Update on Mac OS X El Capitan or YosemiteStep #1. Pull
- 0 down vote I’m 99.44% sure that you cannot either cd or pushd t
- What is a template?A template is a master image of a virtual machine that you can use to