howto simulate packages/namespaces. create private classes
Moderator: General Moderators
howto simulate packages/namespaces. create private classes
Any idea how could I simulate either "functionality" in php.
Last edited by jmut on Thu Aug 31, 2006 1:15 am, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
It's usually done in pseudo fashion:
Code: Select all
class nameSpace_className....- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Just to squelch that myth:Hockey wrote:Hmmmm...I haven't tried it...good thing...but I thought PHP5 supported nested classes???
Code: Select all
[feyd@home]>php -r "class foo{ class bar{} }"
Parse error: parse error, unexpected T_CLASS, expecting T_FUNCTION in Command line code on line 1
[feyd@home]>php -v
PHP 5.1.5 (cli) (built: Aug 15 2006 23:54:56)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
with Xdebug v2.0.0beta6, Copyright (c) 2002, 2003, 2004, 2005, 2006, by Derick Rethans- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I don't know if you have followed the terms 'packages' or 'namespace' as used over the years. I assume that you mean the Java/C# style that derive from Ada. I would recommend taking some time to read the lengthy discussions within the PHP Group about implementing some kind of functionality like this. I think those who think that this is a 'super cool' and 'must have' feature may be sorely disappointed at what is finally implemeted in PHP. And the idea that it gets rid of long names have not seen the reality in other languages where the fully qualified name still often needs to be used.
(#10850)
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
What more could a namespace be, other than an additional errr..ummm....namespacearborint wrote:I don't know if you have followed the terms 'packages' or 'namespace' as used over the years. I assume that you mean the Java/C# style that derive from Ada. I would recommend taking some time to read the lengthy discussions within the PHP Group about implementing some kind of functionality like this. I think those who think that this is a 'super cool' and 'must have' feature may be sorely disappointed at what is finally implemeted in PHP. And the idea that it gets rid of long names have not seen the reality in other languages where the fully qualified name still often needs to be used.
Just offers an additional level of scope resolution...
Like nesting classes, but without performance penalties...at least I wouldn't think so in compiled languages
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I'm pretty sure he mentioned that...Hockey wrote:There is a petition to have namespaces in PHP
Yes, yes he did mention that.arborint wrote:I would recommend taking some time to read the lengthy discussions within the PHP Group about implementing some kind of functionality like this. I think those who think that this is a 'super cool' and 'must have' feature may be sorely disappointed at what is finally implemeted in PHP.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
ok, maybe I didn't ask the right question.
What I really want is to separate a system on different subsystems(packages).
Let say this could be achieved with a proper naming convention of classes etc.
The problem actually is...how I define for example several classes as interface for a certain package(so other packages use ONLY this one/two classes and are NOT able to see/use the other classes.).
Something like...how to simulate private classes declaration (like in JAVA - I am still noob in java but think they have such thing).
What I really want is to separate a system on different subsystems(packages).
Let say this could be achieved with a proper naming convention of classes etc.
The problem actually is...how I define for example several classes as interface for a certain package(so other packages use ONLY this one/two classes and are NOT able to see/use the other classes.).
Something like...how to simulate private classes declaration (like in JAVA - I am still noob in java but think they have such thing).