TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-17-2008, 11:15 PM   #1 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default PHP Namespace Issue - What do you guys think?

Now, I don't know a whole lot about this topic, as I've not been keeping up with the Jones', as it were. I'm quite rusty in terms of PHP news, and so perhaps other people could explain it better for me. It would be appreciated!

As far as I can see, the problem with the namespaces is when there is a function inside a namespace, outside of a class, then there arises a naming problem. It was explained well to me by a friend of mine called Kalle.
  • namespace TalkPHP::Test; function Talk() {}
  • namespace TalkPHP; class Test { public function Talk() {} }

That is the problem as I see it. How does PHP know where it's going when you make the following declaration:

php Code:
use Namespace TalkPHP;
Test::Talk();

PHP would surely get confused there, and that's the problem. It wouldn't know which to call because they've allowed functions to be placed outside of classes, but inside namespaces. I don't believe other languages, such as ASP, or perhaps Java, allow that. Any items inside a namespace have to be in a class. Although I've not worked with either of those languages, so I don't know if that's true.

I personally believe that no functions should be allowed to be placed inside namespaces, without an accompanying class. It seems silly to me. Surely you'll be using namespaces in an OOP environment, and in OOP programming, I don't remember the last time I required a custom function outside of a class. Then again though, I have used static functions inside of classes to mimic namespaces, in absence of namespaces in earlier versions of PHP.

Many have suggested different characters instead of the double colon (::) to access a namespace. What do other people think to this problem, and what's the best way to overcome it, in your humble opinion?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-18-2008, 02:54 PM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Hmm tis an interesting problem, the only ways I can think of is to:

A: not allow functions inside a namespace but not in a class.
B:
change the character to access namespaces.
C:
Not allow you to name classes with the same names as namespaces.

From the sounds of it with current PHP 5.3.0 implementation of namespaces the only way to successfully call the static is to instantiate the class and call the static like:
PHP Code:
$p =  Test();
$p->Talk(); 
otherwise it will call the function inside the Test namespace.

or perhaps use reflection?
PHP Code:
$p = new ReflectionMethod('Test''Talk');
$p->invoke(NULL); 
Will be interesting to se how they resolve it.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 10-18-2008 at 07:01 PM. Reason: speeeeling
sketchMedia is offline  
Reply With Quote
Old 10-26-2008, 01:39 AM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

This is the solution they came up with: php.internals: </endnamespacediscussion>

Namespace separator is now a backslash, so TalkPHP\r\n is now a valid namespace. What do we all think?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-26-2008, 04:25 AM   #4 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

php just keeps getting nastier and nastier to work with. They really need to clean it up. They need to make an entire version where they just clean up everything. Have you ever noticed that if you inherit a php application from another developer it is always so much harder to follow then a coldfusion, or asp.net app. Whats the deal with that. This case as you mentioned wildhoney is just another example of this mess being created.
CoryMathews is offline  
Reply With Quote
Old 10-26-2008, 07:09 AM   #5 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

I don't think PHP is necessarily getting harder to work with because of poor design but because some of the more advanced concept such as Namespaces can't be dealt with the KISS manner PHP is so famous for. If it stuck to that I think it would turn into PHP's Achilles's Heel.
Enfernikus is offline  
Reply With Quote
Old 10-26-2008, 03:58 PM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Argh noooo, sigh.

Sure it solves the problems with namespaces but it looks ugly and will confuse people. not to mention making IDE's and editors go insane trying to parse the namespaces as escape sequences.

What was wrong with just poping an error when a name collision occurs?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 10-28-2008, 02:24 PM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

This makes in interesting read, its a transcript of an IRC discussion with some PHP's developers
http://wiki.php.net/_media/rfc/php.n...or&cache=cache
There is quite alot but its pretty interesting.

I still think this ambiguity issue need not exist, if people just thought about how they write their apps! But it seems the PHP devs want to mollycoddle the lesser mortals that are PHP users, therefore resulting in this rather hackish looking 'patch', thats just my opinion.
_____________
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 10-28-2008 at 04:38 PM.
sketchMedia is offline  
Reply With Quote
Old 10-28-2008, 02:34 PM   #8 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Doh! double post, *sigh* fail
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 10-28-2008 at 03:10 PM.
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:31 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design