(to the list this time......)
I haven't really tested any off this code but heres how I think you could do
it.

First create a wrapper script that does something along the lines of

<?php
    $before_vars = get_defined_vars();
    $before_functions = get_defined_functions();
    $before_classes = get_declared_classes();
    include($argv[1]);
    $after_vars = get_defined_vars();
    $after_functions = get_defined_functions();
    $after_classes = get_declared_classes();

    $file_info = array();
    $file_info['vars'] = array_diff($after_vars,$before_vars);
    $file_info['funcs'] = array_diff($after_functions,$before_functions);
    $file_info['classes'] = array_diff($after_classes,$before_classes);

    print json_encode($file_info);
?>

The above script only kinda works. I don't think array_diff works on
multi-dimensional arrays. But you get the idea. You could also call
get_defined_constants() if you needed those. That script should output
something you will be able to read/parse. I put json cause its easy.

Then in your other script do something along the lines of:

<?php
    exec('/usr/bin/php wrapper.php include1.php',$file1_output);
    exec('/usr/bin/php wrapper.php include2.php',$file2_output);
    //compare $file1_output with $file2_output
?>

I think with a little tweaking that should hopefully get you what you need.
Good luck.

-Kevin-


On 10/29/07, Joshua Simpson <[EMAIL PROTECTED]> wrote:
>
> 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
>

_______________________________________________

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

Reply via email to