Page 1 of 2
howto simulate packages/namespaces. create private classes
Posted: Mon Aug 28, 2006 9:31 am
by jmut
Any idea how could I simulate either "functionality" in php.
Posted: Mon Aug 28, 2006 11:44 am
by Dale
eh?

Posted: Mon Aug 28, 2006 3:53 pm
by feyd
It's usually done in pseudo fashion:
Posted: Mon Aug 28, 2006 8:32 pm
by Ambush Commander
Yep. The main limitation with this is that class names get big really fast, and there's no `use namespace` to come to the rescue.
Posted: Mon Aug 28, 2006 8:33 pm
by alex.barylski
Hmmmm...I haven't tried it...good thing...but I thought PHP5 supported nested classes???
Oh well...

Posted: Mon Aug 28, 2006 8:37 pm
by feyd
Hockey wrote:Hmmmm...I haven't tried it...good thing...but I thought PHP5 supported nested classes???
Just to squelch that myth:
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
Posted: Mon Aug 28, 2006 9:14 pm
by Christopher
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.
Posted: Mon Aug 28, 2006 9:28 pm
by alex.barylski
arborint 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.
What more could a namespace be, other than an additional errr..ummm....namespace
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

Posted: Mon Aug 28, 2006 9:32 pm
by Christopher
You'll have to do some reading to find out.
Posted: Mon Aug 28, 2006 9:39 pm
by alex.barylski
LOL
There is a petition to have namespaces in PHP

Posted: Mon Aug 28, 2006 9:42 pm
by feyd
Hockey wrote:There is a petition to have namespaces in PHP

I'm pretty sure he mentioned 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.
Yes, yes he did mention that.
Posted: Mon Aug 28, 2006 10:01 pm
by alex.barylski
Ok...but he didn't say *petition* just disscussions...
Posted: Mon Aug 28, 2006 10:06 pm
by feyd
splitting hairs.
Posted: Tue Aug 29, 2006 1:32 am
by jmut
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).
Posted: Tue Aug 29, 2006 9:20 am
by feyd
Write a class/interface that will act as a superclass/superinterface by implementing/referencing all the subclasses/subinterfaces. Use type hinting to require this superclass/superinterface.