Cool i do like the idea of havin the namespace keyword
for defining namespaces....
namespace foo
{
}
class bar
{
}
calling $foo = new foo(); shouldn't work
don't think you should ever have an 'instance'
of a namespace. namespaces should be used for static uses.
how about
//default namespace is foo
namespace class foo
{
function strlen()
{
}
function test()
{
return strlen(); //calls foo::strlen
}
}
class bar
{
// default namespace is global
function strlen()
{
}
function test()
{
return strlen(); //calls main::strlen
}
}
namespace foobar
{
function strlen()
{
}
function test()
{
return strlen(); //calls foobar::strlen
}
}
$foo = new foo();
$bar = new bar();
$foobar = new foobar(); //error - no class foobar
foobar::strlen(); //works
something like that...
and having a namespace with no class
can only have static members and functions.
--- Andi Gutmans <[EMAIL PROTECTED]> wrote:
> There is another option.
> We could have an additional reserved word called "namespace" which would be
> exactly the same as a class but when you call a method of the namespace the
> scope would change to it like it does today in ZE2 for classes (i.e.
> lookups for functions would be first local to the namespace and only then
> to the global scope). Calling a method on a class would not switch into the
> classes namespace and its methods would still need to be called either by
> $this->method() or self::method(). In both cases, accessing the
> classes/namespaces static variables would be via self::$var in order not to
> mix it up with the functions local variables (which is a very clean way of
> separating the two). Also we could make classes defined as namespaces not
> to be instantiable.
> So we could have the following:
>
> <?
> namespace Foo {
class Foo implements namspace
{
}
> function strlen()
> {
> }
> function hello()
> {
> strlen(); <-- calls self::strlen();
> main::strlen(); <-- calls global strlen();
> self::strlen(); <-- calls self::strlen();
> }
> }
>
> class Bar {
> function strlen()
> {
>
> }
> function hello()
> {
> strlen(); <-- calls main::strlen();
> main::strlen(); <-- calls global strlen();
> self::strlen(); <-- calls self::strlen();
> }
> }
> }
>
> I'm not sure if this won't just end up being confusing because we'd have
> two things which are extremely similar with just minor differences in
> semantics but it's an option.
>
> Andi
>
> At 10:35 AM 2/8/2002 -0800, brad lafountain wrote:
> >Yeah it has bit me too...
> >I would totaly be for getting rid of the "default" namespace
> >and force developers to use $this-> it pretty much has become
> >normal practice... i really don't like the main namespace ither.
> >
> >Just my thoughts....
> > - Brad
> >
> >--- Harald Radi <[EMAIL PROTECTED]> wrote:
> > >
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > > this is exactly what affects me and what i mean with 'a lot'
> > >
> > > > The question is how often does this breakage actually happen
> > > > in real life
> > > > and not theoretically on the mailing list.
> > > >
> > > > >-------
> > > > >Script as follows will be executed w/o any error
> > > > >and gives totally wrong result.
> > > > >
> > > > >This is really "bad" BC problem, is't this?
> > > > >
> > > > ><?php
> > > > >
> > > > >compute_rate() {
> > > > > // do standard rate calc here
> > > > > return $some_rate;
> > > > >}
> > > > >
> > > > >class A() {
> > > > > function get_rate($is_class_specific_rate) {
> > > > > if (%is_class_specific_rate) {
> > > > > // compute class specific rate
> > > > > return $this->compute_rate();
> > > > > }
> > > > > else {
> > > > > // use standard rate function
> > > > > return compute_rate();
> > > > > }
> > > > > }
> > > > >
> > > > > function compute_rate() {
> > > > > // do a little different rate calc here
> > > > > return $some_rate;
> > > > > }
> > > > >}
> > > > >
> > > > >?>
> > >
> > > -----BEGIN PGP SIGNATURE-----
> > > Version: PGP 7.0.4
> > >
> > > iQA/AwUBPGQYcK1+myS9SSHxEQIoVgCg+mM26j4ZsrwhYNEet8NJFlE3eVYAoOIh
> > > EpCvN8NynvHGu54e63kNkzJ6
> > > =GuQI
> > > -----END PGP SIGNATURE-----
> > >
> >
> >
> >__________________________________________________
> >Do You Yahoo!?
> >Send FREE Valentine eCards with Yahoo! Greetings!
> >http://greetings.yahoo.com
>
__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php