[turba] Advanced search - defaults to OR?

John Dalbec jpdalbec at ysu.edu
Fri Nov 7 09:22:36 PST 2003


In turba/lib/Source.php:
      * @param const $match       (optional) Do an 'and' or an 'or' search 
(defaults to TURBA_SEARCH_AND).
...
     function search($search_criteria, $sort_criteria = 'lastname', $match = 
null, $sort_direction = 0)
...
         $results = $this->driver->search($fields, array_values($this->map), 
$strict_fields, $match);

In turba/lib/Driver/ldap.php:
      * @param const $match   Do an 'and' or an 'or' search (defaults to 
TURBA_SEARCH_AND).
      *
      * @return              Hash containing the search results.
      */
     function search($criteria, $fields, $strict_fields = array(), $match = 
TURBA_SEARCH_AND)
     {
         if ($match === TURBA_SEARCH_AND) {
             $glue = '(&';
         } else {
             $glue = '(|';
         }

Obviously someone thought that setting $match to null in the function call would 
cause the driver search function to fill in the default value.  This doesn't 
seem to be happening here.

The PHP manual has an annotation:
 >function foo($bar=3) {
 >  if (!isset($bar)) {
 >    echo "I'm not set to my default value";
 >}
 >
 >and if you do
 >
 >foo($some_unset_variable);
 >
 >the $bar variable does not adopt default value (3) as one might expect but it 
 >is not set.

Would it make sense to change the Source.php default to an explicit 
TURBA_SEARCH_AND?  Or would it be better to change the code to:

         if ( isset($match) ) {
             $results = $this->driver->search($fields, array_values($this->map), 
$strict_fields, $match);
         } else {
             $this->driver->search($fields, array_values($this->map), 
$strict_fields);
         }

Thanks,
John



More information about the turba mailing list