[development] low hanging fruit for Drupal 6: variable defaults

Syscrusher syscrusher at 4th.com
Thu May 3 18:51:40 UTC 2007


On Thursday 03 May 2007 14:29, Robin Monks wrote:
> New names for variable functions--

Here's a suggestion:

    string variable(string $name, string $namespace='', string $value=NULL)

Semantics:

    variable($name)
       returns the value of the specified variable in the current module's
       namespace (or the Drupal system namespace, if you prefer), or returns
       the default if not defined, or returns NULL if no default

    variable($name, $namespace)
       returns the value of the specified variable in the specified namespace,
       or returns the default if not defined, or returns NULL if no default

    variable($name, $namespace, $value)
       stores $value for the specified variable in the specified namespace,
       if $value is not null. Returns $value as-stored, both to preserve
       semantic consistency AND to reflect any data changes done by the
       variable-handling code (for instance, if it did an implied trim()).
       For now, probably a straight pass-through.

And we add one function that typically would be used only by deinstalls:

    boolean variable_unset(string $name, string $namespace)
       removes the specified variable from storage permanently, returning TRUE
       if successful or if the variable already didn't exist, FALSE if there
       was some kind of database error or if the $namespace didn't exist. In
       other words, missing $name in valid $namespace is okay, just a no-op,
       but invalid $namespace is an error condition.

The behavior of variable() is consistent with similar functions I've worked
with in other environments, such as REXX's GLOBALV function on mainframes.
It also would allow a fairly easy wrapper for legacy compatibility.

Scott

-- 
-------------------------------------------------------------------------------
Syscrusher (Scott Courtney)          Drupal page:   http://drupal.org/user/9184
syscrusher at 4th dot com            Home page:     http://4th.com/   


More information about the development mailing list