Prev: open .zip from memory...
Next: Join me on Multiply
From: "Matt Palermo" on 4 Oct 2010 10:24 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 <?php use \this\is\my\custom\namespace\Item as nsItem; ?> file: index.php <?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
From: "Matt Palermo" on 5 Oct 2010 11:41 I'm assuming there is no way to make a global alias. Can anyone confirm/deny this? ""Matt Palermo"" wrote in message news:5E7B8989448B45DBBEEB6FB89B3F350E(a)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 <?php use \this\is\my\custom\namespace\Item as nsItem; ?> file: index.php <?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
From: David Harkness on 5 Oct 2010 12:07 On Tue, Oct 5, 2010 at 8:41 AM, Matt Palermo <palermomatt(a)gmail.com> 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
|
Pages: 1 Prev: open .zip from memory... Next: Join me on Multiply |