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)
- namespace in php demo tutorial (2)
- script login php5 3 (2)
- php namespaces tutorial (2)
- php 5 3 namespace tutorial (2)
- simple namespace script in php 5 3 (1)
- php namespace tutorial#hl=en (1)
- php5 3 login script (1)
- php5 3 tutorial (1)
- php5 script use namespace (1)
- simple php5 3 mysql login script (1)
- saving namespace php (1)
- simple login script in php 5 3 with mysql (1)
- 5 3 namespace tutorial (1)
- php namespace tutorial video (1)
- php 5 namespaces tutorial (1)
- addbookmark prestashop firefox (1)
- fpdf php 5 3 internal server error (1)
- get_meta_tags cpanel (1)
- namespace in php5 tutorial (1)
- namespace php tutorial (1)
- php 5 3 login script tutorial (1)
- php 5 3 namespaces (1)
- php 5 3 namespaces tutorials (1)
- php 5 3 use namespace (1)
- using namespaces in php 5 3 tutorial (1)
You will also be interested in ,
- Find the string and then the line number using php from text file
- How To Set And Get Cookies Using PHP
- Display Tags in wordpress
- Finding size of a directory using php
- Getting Remote Webpage Info Using PHP
- PHP Most Potentially Dangerous Feature, Secure It Today PHP Secrets
- Output buffering using ob_start in php
- Simple Ajax with PHP click tracker
- Using PHP_SELF best practices
- Get textbox value from dropdown using ajax and php

