By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

another argument passing problem :-(

P: n/a
Hi all,

Sorry to present you all with another boring problem but I've spent
all day trying to get this to work with no success.

Below is a function to which I pass the argument &$myCell (which is an
instance of my class "Cell"). I am not sure whether it is necessary
or desirable to use the '&' and I've noticed that this subject seems
to be a source of considerable debate in this group (is this the
method used implicitly in java?).

My problem here is that the lines;

$html .= $newCell->getAttributes();
$html .= $newCell->getData();

do not work. They refer to functions within the Cell class but the
error that comes up is;

Fatal error: Call to a member function on a non-object
function addCell(&$myCell)
{
$html="<td>";
$html .= $newCell->getAttributes();
$html .= $newCell->getData();

return $html .= "</td>";
}
If it should help in identifying the problem, the remainder of this
class is printed below. Thanks for your help ;-)

Andy

--------------------------------------------------------------------------
//test data
$testTable = new Table('border="1" summary="Test table"');
$c1 = new Cell("skdj", "bgsdlr");
$c2 = new Cell('jzhb', 'sjbvf');
$c3 = new Cell('zjskdbv', 'jsdbsjkv');
$c4 = new Cell('jzsdcg', 'zkdjbd');
$r1 = array($c1, $c2);
$r2 = array($c3, $c4);
$testTable->startTable();
$testTable->addRow($r1);
$testTable->addRow($r2);
$testTable->stopTable();

//Table Class
class Table
{
var $attributes;
function Table($attributes="")
{
$this->attributes = $attributes;
}
function startTable()
{
echo $html = "<table " .$this->attributes . "\n";
}
function stopTable()
{
echo $html = "</table>";
}
function addRow($newRow)
{
$html="<tr>";
for( $i ; $i < count($newRow) ; $i++ )
{
$cells=$newRow[i];
$html .=$this->addCell($cells);
}
echo $html .="</tr>";
}
}
?>
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Andy wrote:
(snip)
Fatal error: Call to a member function on a non-object
function addCell(&$myCell)
{
$html="<td>";
$html .= $newCell->getAttributes();
Where does $newCell come from? :)
$html .= $newCell->getData();

return $html .= "</td>";
}


Turn on error reporting for PHP and it will tell you when you use
unintialized variables.

Insert

error_reporting(E_ALL);
ini_set('display_errors', '1');

at the top of your scripts (or change php.ini)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

P: n/a
The solution is:

<table>
<tr>
<td>Pluralitas non est ponenda sine neccesitate</td>
</tr>
</table>

"Andy" <an************@yahoo.co.uk> wrote in message
news:b2**************************@posting.google.c om...
Hi all,

Sorry to present you all with another boring problem but I've spent
all day trying to get this to work with no success.

Below is a function to which I pass the argument &$myCell (which is an
instance of my class "Cell"). I am not sure whether it is necessary
or desirable to use the '&' and I've noticed that this subject seems
to be a source of considerable debate in this group (is this the
method used implicitly in java?).

My problem here is that the lines;

$html .= $newCell->getAttributes();
$html .= $newCell->getData();

do not work. They refer to functions within the Cell class but the
error that comes up is;

Fatal error: Call to a member function on a non-object
function addCell(&$myCell)
{
$html="<td>";
$html .= $newCell->getAttributes();
$html .= $newCell->getData();

return $html .= "</td>";
}
If it should help in identifying the problem, the remainder of this
class is printed below. Thanks for your help ;-)

Andy

--------------------------------------------------------------------------
//test data
$testTable = new Table('border="1" summary="Test table"');
$c1 = new Cell("skdj", "bgsdlr");
$c2 = new Cell('jzhb', 'sjbvf');
$c3 = new Cell('zjskdbv', 'jsdbsjkv');
$c4 = new Cell('jzsdcg', 'zkdjbd');
$r1 = array($c1, $c2);
$r2 = array($c3, $c4);
$testTable->startTable();
$testTable->addRow($r1);
$testTable->addRow($r2);
$testTable->stopTable();

//Table Class
class Table
{
var $attributes;
function Table($attributes="")
{
$this->attributes = $attributes;
}
function startTable()
{
echo $html = "<table " .$this->attributes . "\n";
}
function stopTable()
{
echo $html = "</table>";
}
function addRow($newRow)
{
$html="<tr>";
for( $i ; $i < count($newRow) ; $i++ )
{
$cells=$newRow[i];
$html .=$this->addCell($cells);
}
echo $html .="</tr>";
}
}
?>

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.