[UPHPU] Include file namespace collision detection

Jonathan Duncan jonathan at bluesunhosting.com
Tue Oct 30 17:03:47 MDT 2007


On 30 Oct 2007, at 09:49, Joshua Simpson wrote:

> Wow, a lot of responses, I always appreciate the vigor of the UPHPU  
> list.
>
> Here's how I was thinking it would work.  I'm pretty busy at work,  
> so I
> haven't even tested it, but if I get some free time at lunch I'll  
> look at
> it:
> function check_namespaces($includefile1, $includefile2) { //  
> ideally, I'd
> want to allow for a unspecified amount of arguments
>  $tokens[0] = get_all_tokens($includefile1);
>  $tokens[1] = get_all_tokens($includefile2);
>  $compare_stack = array();
>  for($i=0; $i<count($tokens); $i++) {
>    $compare_stack[$i] = array();
>
>    foreach($tokens[$i] as $token) {
>      if(is_array($token)) {
>         list($token, $text) = $token;
>        switch($token) {
>          case "T_CLASS":
>              array_push($compare_stack[$i] ,  $text);
>        .... more  token searching and pushing names onto stack if it  
> takes
> up namespace
>
>        }
>     }
>  }
>  // compare the arrays
> }
>
> Sorry I had to cut that short, but I think you get the gist.  With  
> simple
> include files, you could even do some sort of pseudo-namespace magic
> yourself (for constants, variables, etc).  Maybe with some exec  
> magic, you
> could even import classes to a namespace, but I doubt it.
>
> Anyways, I gotta put out a fire, tell me what you guys think.
>

You probably already know about Reflection, but I recently learned  
about it.  If you have not seen it, check it out:

http://www.php.net/manual/en/language.oop5.reflection.php

Might have something that could help you with this issue.


More information about the UPHPU mailing list