Reply to $this is undefined in a class

Your name:

Reply:


Posted by Peter Jay Salzman on 09/29/88 11:33

I have a very simple class: 2 variables, 3 methods. PHP is telling me that
$this is undefined in one of the functions, but is defined and has the
expected value in the other two functions.

In the code before, $this is defined in LinksClass() and navbarLinks(), but
not selectGroup(). I've never seen anything like this before. What could
possibly be causing this?





<?
require_once('classDatabase.php');


Class LinksClass
{
var $groups;
var $links;



function LinksClass()
{
$db = new DatabaseClass;
$tblLnkGrp = 'pbtbl_lnkgrp';
$tblLinks = 'pbtbl_links';

// Store linkgroups in array indexed by linkgroup id.
//
$db->query("SELECT * FROM $tblLnkGrp");
while ( $row = $db->fetchArray() )
$this->groups[$row['id']] = $row;

// Store links in array indexed by link id.
//
$db->query("SELECT * FROM $tblLinks");
while ( $row = $db->fetchArray() )
$this->links[$row['id']] = $row;

}





// Creates a select menu of the linkgroups. UNUSED
//
function selectGroup( $activeGroupId = '' )
{
echo '<pre>'; print_r($this); echo '</pre>'; exit;
$output = '<select name="lnkGrp">';

foreach ( $this->groups as $group )
{
$grpId = $group['id'];
$grpName = $group['name'];
$selected = ( $activeGroupId == $grpId ) ? 'selected="selected"' : '';
$output .= "<option value=\"$grpId\" $selected>$grpName</option>\n";
}

echo $output . '</select>';
}





function navbarLinks()
{
echo '<div id="nav-links">';
StartNavGroup();
NavGroupHeading(LINKS);

foreach ( $this->links as $lnk )
NavItem($lnk['url'], $lnk['text'], $lnk['title']);

EndNavGroup();
echo '</div> <!-- nav-links -->';
}


}

?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация