Women in Technology

Hear us Roar



Article:
  An Introduction to PEAR
Subject:   how can I tell if PEAR is installed?
Date:   2007-07-24 07:52:05
From:   tomski
Response to: how can I tell if PEAR is installed?

I get an error when running getPackages()


Warning: Invalid argument supplied for foreach() in D:\xampplite\php\pear\PEAR\Info.php on line 235


Here's the whole script for packages, Line 235 is bold.


function getPackages()
{
$latest = @$this->r->call('package.listLatestReleases');
$available = $this->reg->listPackages();
if (PEAR::isError($available)) {
echo '<h1 style="font-size: 12px;">An Error occured fetching the package list. Please try again.</h1>';
return FALSE;
}
if (!is_array($available)) {
echo '<h1 style="font-size: 12px;">The package list could not be fetched from the remote server. Please try again.</h1>';
return FALSE;
}
natcasesort($available);
if ((PEAR::isError($latest)) || (!is_array($latest))) {
$latest = FALSE;
}
$packages = '';
foreach ($available as $name) {
$installed = $this->reg->packageInfo($name);
if (strlen($installed['package']) > 1) {
if (!isset($old_index)) {
$old_index = '';
}
$current_index = $name{0};
if (strtolower($current_index) != strtolower($old_index)) {
$packages .= ' () ';
$old_index = $current_index;
$this->index[] = $current_index;
}
$packages .= '
<h2>' .trim($installed['package']). ' () </h2>
<table>
<tr class="v">
<td class="e">
Summary
</td>
<td>
' .nl2br(htmlentities(trim($installed['summary']))). '
</td>
</tr>
<tr class="v">
<td class="e">
Version
</td>
<td>
' .trim($installed['version']). '
</td>
</tr>
<tr class="v">
<td class="e">
Description
</td>
<td>
' .nl2br(htmlentities(trim($installed['description']))). '
</td>
</tr>
<tr class="v">
<td class="e">
State
</td>
<td>
' .trim($installed['release_state']). '
</td>
</tr>
<tr class="v">
<td class="e">
Information
</td>
</tr>';
if ($latest != FALSE) {
if (isset($latest[$installed['package']])) {
if (version_compare($latest[$installed['package']]['version'],$installed['version'],'>')) {
$packages .= '<tr class="v">
<td class="e">
Latest Version
</td>
<td>
' .$latest[$installed['package']]['version'] . ' (http://pear.php.net/get/' .trim($installed['package']). ')
('. $latest[$installed['package']]['state']. ')
</td>
</tr>';
}
}
}
$packages .= ' <tr>
<td colspan="2" class="v">Top (#top) </td>
</tr>
</table>';
}
}
?>
<h2>PEAR Packages () </h2>
<table style="padding: 3px;">
<tr>
<td class="e">
Index
</td>
</tr>
<tr>
<td class ="v" style="text-align: center">
<?php
foreach ($this->index as $i) {
?>

| <?php echo strtoupper($i); ?> (#<?php echo $i; ?>)
<?php
}
?>|
</td>
</tr>
</table>


<?php
echo $packages;
}


<b>Thanks for for any help. I would like to view my installed packages.


Tom