[Pmwiki-users] Dev Q3: Avoiding Problems With Variable Scope in Add-On Scripts

Patrick R. Michaud pmichaud
Tue Mar 30 08:46:48 CST 2004


On Tue, Mar 30, 2004 at 08:29:35PM -0800, Steven Leite wrote:
> 
> Example:  In X-Chat .. $NickName, $ServerName, $CodeBase, $Height, $Width,
> etc .. these are all at
> the top of the script.  

In general, variables names such as $Width and $Height are too generic
to be named that way.  In addition, it may be better to allow width and
and height to be specified using CSS properties instead of HTML tag
attributes.

Also, PmWiki generally takes the approach of using a variable to define
an entire tag, as opposed to defining separate variables for each attribute
of the tag.

In the case of x-include, I would use a array for the defaults instead of 
individual global variables, especially since they get converted to an
array later.  Thus:

   SDVA($XInclude,array(
     'width' => '600',
     'height' => '400',
     'align' => 'default',
     'scroll' => 'default',
     'border' => 'default'));

The SDVA function sets the values of array elements if the elements
don't already have a value.  Thus someone can locally customize the 
value by simply doing 

   $XInclude['width'] = '400';

and it becomes real unlikely that there would be conflicts with variables
in other scripts.

Pm



More information about the pmwiki-users mailing list