Is it possible to create a global namespace alias?

Is it possible to create a global namespace alias?

am 03.10.2010 18:09:56 von Matt Palermo

------=_NextPart_000_01DE_01CB62F3.E4844600
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable

ï»=BFIs it possible to create a global namespace alias in PHP or =
does the alias have to be defined in EVERY file that I use? Here is an =
example:

file: main.php
use \this\is\my\custom\namespace\Item as nsItem;
?>


file: index.php
require_once â€=9Cmain.phpâ€=9D;

// Attempt to use namespace alias defined in main.php file
nsItem::test();
?>


The above code doesnâ€=99t work for me. The namespace alias defined =
in the main.php file isnâ€=99t accessible in the index.php file. Is =
there a way to make the â€=9CnsItemâ€=9D alias a =
â€=9Cglobalâ€=9D one, so that I donâ€=99t have to define it =
in EVERY file that I want to use?

-Matt
------=_NextPart_000_01DE_01CB62F3.E4844600--

Re: Is it possible to create a global namespace alias?

am 05.10.2010 17:41:29 von Matt Palermo

I'm assuming there is no way to make a global alias. Can anyone
confirm/deny this?



""Matt Palermo"" wrote in message
news:5E7B8989448B45DBBEEB6FB89B3F350E@Rachet...

Is it possible to create a global namespace alias in PHP or does the alias
have to be defined in EVERY file that I use? Here is an example:

file: main.php
use \this\is\my\custom\namespace\Item as nsItem;
?>


file: index.php
require_once “main.php”;

// Attempt to use namespace alias defined in main.php file
nsItem::test();
?>


The above code doesn’t work for me. The namespace alias defined in the
main.php file isn’t accessible in the index.php file. Is there a way to
make the “nsItem” alias a “global” one, so that I don’t have to define it in
EVERY file that I want to use?

-Matt


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

Re: Re: Is it possible to create a global namespace alias?

am 05.10.2010 18:07:10 von David Harkness

--001636832ef46fa1150491e0da32
Content-Type: text/plain; charset=ISO-8859-1

On Tue, Oct 5, 2010 at 8:41 AM, Matt Palermo wrote:

> I'm assuming there is no way to make a global alias. Can anyone
> confirm/deny this?
>

I reread the documentation on namespaces, and from what I can tell this is
no way to do it. Each file maintains its own active namespace *at compile
time*. This means you can't even get around it with eval() or including
another script to set it.

I can't say I'm positive someone won't find a way around it, but short of an
extension I don't see one.

David

--001636832ef46fa1150491e0da32--