To use Foo we call him by its fancy new name. This is just the referring to a file with its absolute path.

<?php
require ‘foo.php’;
$foo = new \Acme\Tools\Foo();
?>

And that’s really it. Adding a namespace to a class is like organizing files from one directory into a bunch of subdirectories. To refer to a class use it fully qualified name starting with a \.
Since running around but this giant name is a drug, let’s add a shortcut. The use statement let us call \Acme\Tools\Foo() class by a nickname.

Great. But what about old school none name space php classes. For that le’s pick on datetime – a handy class that’s called a php. And got some new bells and whistles in php 5.3. For ever and ever creating a new datetime object is the same – new datetime().

The use statement looks silly. But it tells php that when you use datetime you mean a none name space class, state time. Or give of the beginning \ with the use statement. Everything works completely the same with or without it.

Share this entry

http://en.softmaker.kz/wp-content/uploads/2014/08/Namespace.png300400softmakerhttp://en.softmaker.kz/wp-content/uploads/2015/11/logo_site1.pngsoftmaker2014-08-31 00:00:002015-11-21 16:14:43What are namespaces in the PHP language?

Categories

The article deals with setting up XAMPP, which must be done so that the local web-server Apache work properly. After reading the article you will be able to set up virtual hosts and quickly correct any error that prevents proper operations of the mod_rewrite mode in the file .htacces.