On 10/29/07, Jonathan Duncan <[EMAIL PROTECTED]> wrote:
>
>
>
> Call me dense, but, wha huh?  What exactly are you trying to do now?


A namespace is where particular names are stored.  Let's say we have an
include file:
include1.php
<?php
$x = 5;
$y = 7;
$z = 9;

function add_em($a, $b, $c) {
  return $a + $b + $c;
}
?>

This file's namespace is filled with: x, y, z, and add_em

Let's say we have another include file:
include2.php
<?php
$str1 = 'blah';
$str2 = 'more blah';

function add_em($a, $b) {
  return $a + $b;
}
?>

This file's namespace consists of str1, str2, and add_em.

Now, in PHP, when you use a require or an include statement, you import that
file's namespace into the GLOBAL namespace.  Besides classes, PHP has no
concept of namespaces (a ridiculous design flaw, that, hopefully, will be
fixed by PHP 6).   So, if I include both of these files in a master file:

master.php
<?php
include_once('include1.php');
include_once('include2.php');
...
some operations
...
add_em(5, 3, 2);
?>

This results in a name collision;  since include2.php is called last, it's
add_em function will be used (since they're all stuffed into the global
namespace, much like a bloated turkey on Thanksgiving).   This can result in
a variety of problems, especially with many developers, and no scaffolding
to catch stuff like this.

What I'm trying to do is inspect the namespaces of included files before
they're included, and raise exceptions (yay, PHP finally added those) if any
detectable collisions arise.

Orson advised me to check out the 'tokens' functions, and I think they have
what I need to make this work.

Sorry if I come off as a bit annoyed, but I'm peeved at having to write PHP.


-- 
-
http://stderr.ws/
"Some pseudo-insightful quote here." - Some Guy

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to