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.
Incoming search terms:
- php namespace tutorial (6)
- php 5 3 interview questions (3)
- php namespaces tutorial (2)
- namespace in php demo tutorial (2)
- script login php5 3 (2)
- php5 3 login script (1)
- php5 3 tutorial (1)
- simple login script in php 5 3 with mysql (1)
- simple namespace script in php 5 3 (1)
- simple php5 3 mysql login script (1)
- using namespaces in php 5 3 tutorial (1)
- php namespace tutorial#hl=en (1)
- php namespace tutorial video (1)
- 5 3 namespace tutorial (1)
- fpdf php 5 3 internal server error (1)
- namespace in php5 tutorial (1)
- namespace php tutorial (1)
- php 5 3 login script tutorial (1)
- php 5 3 namespace tutorial (1)
- php 5 3 namespaces (1)
- php 5 3 namespaces tutorials (1)
- php 5 namespaces tutorial (1)
- windows php5 3 namespaces internal server error (1)
You will also be interested in ,
- Change background color using php for a webpage
- Add rounded edge or corner images using php
- Replacing a string using php
- Using PHP_SELF best practices
- XML Parsing Made Easy
- Get youtube video screenshot using simple php and javascript
- Sort MYSQL data according to the date in php or mysql itself
- Appending string using php to a text file
- Php mysql example image gallery blob storage
- Post Data To Another Website Using cURL In PHP
