This option will reset the home page of this site. Restoring any closed widgets or categories.

Reset

How to use Namespaces in php 5.3 ?

How would you differentiate if the call save() was to save a blogs or save comments? The solution was to use blog_save() or comment_save() before the introduction of classes in which we could write the save() function within the Blog class or the Comment class.Using classes is obviously a much more elegant solution.

Using namespaces, we could simply separate the two functions with the same name very easily:

< ?php
namespace Blog;
function save()
{
echo "Saving the blog!";
}

namespace Comment;
function save()
{
echo "Saving the comment!";
}

// To invoke the functions
Blog\save();    // This prints - Saving the blog!
Comment\save(); // This prints - Saving the comment!
?>

Developers will have to use \ backslash operator to dereference namespaces.

VN:F [1.5.7_846]
Rating: 0.0/10 (0 votes cast)
VN:F [1.5.7_846]
Rating: 0 (from 0 votes)

Related posts:

  1. C# simple console application
  2. working with directories using php

Leave a Reply

Comments (required)

Spam Protected