473,785 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(&$myCel l)
{
$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($attribut es="")
{
$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 1685
Andy wrote:
(snip)
Fatal error: Call to a member function on a non-object
function addCell(&$myCel l)
{
$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('displa y_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>Pluralita s non est ponenda sine neccesitate</td>
</tr>
</table>

"Andy" <an************ @yahoo.co.uk> wrote in message
news:b2******** *************** ***@posting.goo gle.com...
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(&$myCel l)
{
$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($attribut es="")
{
$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
5315
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 is supposed to pass the argument indicated by the menu selection to another php file which uses that argument to make a further (refined) search on the same database. But upon calling the 2nd php file when I try to use the argument passed it...
3
1777
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' in a famous python tool I thought it might still help other people to save some time. I tried to use some method which was documented to write to 'sys.stdout' per default so that changing 'sys.stdout' to bind to another object should allow to...
8
3969
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer http://sourceforge.net/projects/cpp-perfometer http://alexvn.freeservers.com/s1/perfometer.html
1
2538
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 show me a example of how to do this. I was told to pass the arrays from function to function, but i do not know how .... Thanxs if you can help. My code (First two functions only - there's more):
2
15128
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 the outer function, the string.format sets the string-value "System.Object" at the position of {0}. How can i get it work, so that all my values, passed to the outer
188
7255
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 - non-deterministic destructors - Objects can't exist on the stack - Type / Reference Types
3
3407
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 exception constructors? I've noticed that, f.ex., ArgumentException accepts null arguments without raising ArgumentNullException. Obviously, if nothing is to be supplied to the exception constructor, the default constructor should
12
2594
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 by value temporaries are created?(I'm not touching yet the cases where standard allows optimizations from the side of implementations to avoid copying) If so, please quote part of the standard that says that. Assuming it is true, I can imagine two...
17
1685
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
1213
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 anonymous method signature _does_ in fact wind up taking no parameters. But with an anonymous method, you can "capture" any variable accessible in the method in which the anonymous method is declared. So rather than
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10162
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.