[UPHPU] Include file namespace collision detection

Joshua Simpson std3rr at gmail.com
Tue Oct 30 09:49:11 MDT 2007


On 10/29/07, David Boucha <boucha at gmail.com> wrote:
>
>
> This would be a total hack, but could you just read the file into a
> variable and then run some regex-foo to get the names of any classes
> and methods?


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.


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


More information about the UPHPU mailing list