[SPT/CWIS] include/SPT--GlobalSearchEngine.php , array_merge() and PHP 5.1.6
Jhonatan Tirado
jhonatantiradotiradodeep at gmail.com
Mon Apr 30 18:25:50 CDT 2007
Hi.
Recently, I had the following problem:
***Warning*: array_merge()
[function.array-merge<http://peru.campusvirtualsp.org/repositorio/function.array-merge>]:
Argument #1 is not an array in */var/www/repositorio/include/SPT--
GlobalSearchEngine.php * on line *91*
*Warning*: array_merge()
[function.array-merge<http://peru.campusvirtualsp.org/repositorio/function.array-merge>]:
Argument #2 is not an array in */var/www/repositorio/include/SPT--
GlobalSearchEngine.php * on line *91*
*Warning*: usort()
[function.usort<http://peru.campusvirtualsp.org/repositorio/function.usort>]:
The argument should be an array in */var/www/repositorio/include/SPT--
GlobalSearchEngine.php* on line *100*
*Warning*: array_slice()
[function.array-slice<http://peru.campusvirtualsp.org/repositorio/function.array-slice>]:
The first argument should be an array in */var/www/repositorio/include/SPT--
GlobalSearchEngine.php * on line *106
*
It happened while doing a global search to another friend sites.
Specifically, the following code gave the error:
function PerformSearch($SetSpec, $StartingResult, $NumberOfResults)
{
# for each global search site
$DB =& new SPTDatabase();
$DB->Query("SELECT * FROM GlobalSearchSites");
$SearchResults = array();
while ($SiteInfo = $DB->FetchRow())
{
# retrieve results from site
$SiteSearchResults = $this->SearchSite($SiteInfo, $SetSpec);
# add results to result list
$SearchResults = array_merge($SearchResults,
$SiteSearchResults); **error
}
# sort the results in descending order by search score
function SearchScoreCmp($ResultA, $ResultB)
{
return ($ResultA["Search Score"] == $ResultB["Search Score"]) ?
0
: (($ResultA["Search Score"] < $ResultB["Search Score"])
? 1 : -1);
}
usort($SearchResults, "SearchScoreCmp");
# save number of results found
$this->NumberOfResultsAvailable = count($SearchResults);
# trim result list to match range requested by caller
$SearchResults = array_slice($SearchResults, $StartingResult,
$NumberOfResults);
# return search results to caller
return $SearchResults;
}
It happens when there are not results matching the search criteria. In that
case, $SiteSearchResults would be null. With PHP 4.x, no problem, it
converts null to array on the fly. But PHP 5.x needs to have it explicit.
So, the only thing you have to do is to add (array), to convert the variable
to array on the fly, cause in other way, PHP wouldn't understand the
syntaxis and give you the error:
$SearchResults = array_merge($SearchResults, (array) $SiteSearchResults);
So, if any of you wants to upgrade to PHP 5.x, it's OK. The only thing you
have to do is to add that word (array()) and you're done.
Greetings!
PD: I'm also using MySQL 5.x, Apache 2.x and Ubuntu Server Edition 6.10
--
Jhonatan Hamner Tirado Tirado
Analista Desarrollador
Celular: +51 44 9670126
Lima, Perú
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.scout.wisc.edu/pipermail/spt-cwis-users/attachments/20070430/a7f8bdbc/attachment-0003.html
More information about the SPT-CWIS-Users
mailing list