PHP Namespace Primer Tutorial

PHP Namespace Primer Tutorial

PHP Namespace Primer Tutorial

The concept of a namespace exists in several computer languages, but of those, today we start on a discussion of its encapsulation role with PHP.

A great source of information for information about PHP namespaces is this great link from the “home of PHP” … we always find.

Being as you can do without “namespaces” programming with PHP, let’s hone in on a couple of reasons you may want to make use of them (even so), taken from that aforesaid mentioned link …

  1. Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
  2. Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving readability of source code.

From that same link we modify some of its code to show you some concepts regarding this, having a named “namespace” section code establish its own “strlen($strvar)” function (negating the “\strlen($strvar)” call result).

We have this named “namespace” code set up its own MYCONST constant, and you can see how this works as well.

We don’t use it here, but also, in relation to named “namespace” code, you will want to research from the “home of PHP” the aliasing use of the PHP use keyword.

For today’s PHP code live run we have PHP code you could call mynamespace.php for your perusal. We hope it helps.

If this was interesting you may be interested in this too.

This entry was posted in eLearning, OOP, Tutorials and tagged , , , , , , , . Bookmark the permalink.

3 Responses to PHP Namespace Primer Tutorial

  1. bache says:

    Bonjour ! C’est cool comme site ici !

  2. health says:

    I’m completely concur with your statement or the things that you’ve discussed right here in this web site.

  3. My wife and i ended up being so glad Peter managed to finish up his investigation while using the precious recommendations he had when using the web pages. It’s not at all simplistic to just happen to be releasing information and facts other folks have been selling. We keep in mind we’ve got the website owner to appreciate for this. The entire illustrations you’ve made, the simple website menu, the friendships your site help to engender – it’s got all exceptional, and it’s really letting our son and our family recognize that that issue is fun, and that’s very essential. Thanks for everything!

Leave a Reply to Modular Homes Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>