Quoting Catalin Trifu <[EMAIL PROTECTED]>:
> > <?php
> > class Foo {
> >  const Bar       = 'Foo_Bar';
> >  const Chocolate = 'Foo_Chocolate';
> >  const Target    = 'Foo Target';
> > }
> >
> > $bar = new Foo::Bar();
> > ?>
>
>     Foo::Bar() is taken by php as a function call and then it tries to
> instantate whatever that function returns.
>     This is quite logical behaviour since function calls always end up with
> ().
>     When you call
>     $bar = new Foo::Bar;
>     then the Foo::Bar is definetely refering to constant Bar in class Foo
>
> Cheers,
> Catalin
First of all: thank you Catalin for your thoughts!

Seems logical from that point of view.

According to the list if differences between variables and constants
(http://nl2.php.net/manual/en/language.constants.php) though, they should
pretty much work the same (no difference is mentioned). Thus, when both $bar
and Foo::Bar evaluate to the same value I would expect PHP to do the same
thing. Let me at least hope that the php team has considered many options on
how to deal with this...

If I do want to use the :: notation between PackageName and the actual name of
the class, I'm probably gonna be stuck using smth like:

<?php
class Foo {
  public static function Bar() {
    return new Foo_Bar();
  }
}
?>

Or smth with the __call() function and an (iew) eval() call, since
call_user_func_array() doesn't work on constructors (or so I heard, haven't
tried it).

--
Always consider all options before deciding which object to talk to

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to