473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

another argument passing problem :-(

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
2 1664
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Newbie | last post by:
Hi, I am using creating a drop down menu populated by a call to a postgresql database. The drop down menu is populated correctly (or appears to be) and then upon selecting an item in the menu it...
3
by: Frank Bechmann | last post by:
Eventually most of you will not learn much from this because it's just another event in the 'default argument value gotcha' series, but because it cost me some hours yesterday to spot this 'error'...
8
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
1
by: Foxy Kav | last post by:
Hi everyone, im a first year UNI student doing a programming subject and im stuck on how to get rid of my global variables, char stringarray and char emptystring. I was wondering if anyone could...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
188
by: christopher diggins | last post by:
I have posted a C# critique at http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up the following issues : - unsafe code - attributes - garbage collection -...
3
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
17
by: Summercool | last post by:
I wonder which language allows you to change an argument's value? like: foo(&a) { a = 3 } n = 1 print n
1
by: Peter Duniho | last post by:
On Tue, 14 Oct 2008 10:01:25 -0700, robert.waters <robert.waters@gmail.comwrote: That depends on your definition of "bypasses". Using the anoymous method doesn't remove the restriction; the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.