|
From: <php...@li...> - 2007-09-10 09:32:28
|
Hi,
> code, I didn't actually *use* anything from it, yet, just including it was
> enough to break my application.
how can a temporary variable, which is used only within the Java.inc block, break your
application?
> After some quite substantial investigation I had to learn, that the reason
> was, that the Java.inc file uses a globally visible variable "$version"
$version is a variable which is used only in the if() block. Since php currently doesn't support
name spaces, it is created in the global environment instead. Whether or not an included library
uses temporary bindings in the global environment should not affect a well-written application.
For version 4.2.3 we could turn the code block into a lambda() and immediately invoke it. This way
the bindings are created local to the anonymous function and do not pollute the global env.
> Apparently some other code that I am using also checks for such a variable.
> It expects to find 1.0.0 but now found 5.2.3 (the PHP version I am using)
Isn't it possible to keep your *global variables* in a separate map? BTW: I would prefix all
global variables with appname_ to avoid clashes with other libs. Temporary bindings don't need to
prefixed, though.
> if you use (and then leave around) such globally visible variables, then
> PLEASE make their names VERY unique.
This means that we have to prefix all *temporary* variables with java_. I don't think this is a
good idea.
However, we can and probably should turn global code blocks into anonymous functions and invoke
them immediately.
> I even suggest to NOT use any variable here, but to write this snippet as
> follows:
> ...
> if ((version_compare("5.1.2", phpversion(), ">"))) {
> $msg = '<br><strong>PHP '.phpversion().' too old.</strong><br>\nFor
How does this help? The temp var $msg is also created in the global environment.
Regards,
Jost Boekemeier
__________________________________
Yahoo! Clever - Der einfachste Weg, Fragen zu stellen und Wissenswertes mit Anderen zu teilen. www.yahoo.de/clever
|