473,795 Members | 3,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assigning class objects to variables

Looked all over for the answer to this but can't find it. Maybe I'm
searching for the wrong thing. I'm new to using classes in PHP.

Whenever I try and reference the member's ($line) properties or
functions I either get blank for properties or "Call to a member
function on a non-object" for functions. I'm sure I'm doing something
incorrectly with the assignment.

function LineGroup($clas sarray)
{
$groupout = "";

while ($line = each($classarra y))
{
$groupout .= "<tr><td>".$lin e -> GetCat1Desc()." </td></tr>";
}

return $groupout;
}

also even when I try the following the same problem occurs

function LineGroup($clas sarray)
{
$groupout = "";

$groupout .= "<tr><td>".$cla ssarray[0] ->
GetCat1Desc()." </td></tr>";

return $groupout;
}

Any help would be greatly appreciated.

Thanks, Cory
Jul 17 '05 #1
1 1694
Hi Cory,
while ($line = each($classarra y))
In general you should make loops like this:

reset($classarr ay);
while (list($key) = each($classarra y)) {
$line =& $classarray[$key];

but this will work too:

reset($classarr ay);
while (list($key, $line) = each($classarra y))

but has the disadvantage of copying each object in $classarray when it
is assigned to $line. Copying decreases performance and uses up memory
that is only freed at the end of your script.
$groupout .= "<tr><td>".$cla ssarray[0]->GetCat1Desc( ). "</td></tr>";

I do't know, maybe there is no element with index 0? try:
print_r($classa rray);
then select "view source" in your browser, so that you can see what's in
the array under what keys.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

BTW, i would expect:
$objectarray = array( new SomeClass('firs t'), new SomeClass('seco nd') );

$classarray = array('someclas s', 'someotherclass ');
so that i can do:
if (in_array(get_c lass($objectarr ay[0]), $classarray) )
print "the class of object 0 is in the class array";

just a matter of avoiding misleading names.

Cory Bosma wrote: Looked all over for the answer to this but can't find it. Maybe I'm
searching for the wrong thing. I'm new to using classes in PHP.

Whenever I try and reference the member's ($line) properties or
functions I either get blank for properties or "Call to a member
function on a non-object" for functions. I'm sure I'm doing something
incorrectly with the assignment.

function LineGroup($clas sarray)
{
$groupout = "";

while ($line = each($classarra y))
{
$groupout .= "<tr><td>".$lin e -> GetCat1Desc()." </td></tr>";
}

return $groupout;
}

also even when I try the following the same problem occurs

function LineGroup($clas sarray)
{
$groupout = "";

$groupout .= "<tr><td>".$cla ssarray[0] ->
GetCat1Desc()." </td></tr>";

return $groupout;
}

Any help would be greatly appreciated.

Thanks, Cory


Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1601
by: vanGogh | last post by:
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool. My goal is to: - write an application that can parse XML documents - fill objects (based on the generated classes) with the XML data in element nodes or attributes - assemble the objects so they are contained in their parent - add the resulting object to an arrayList The problem I’m having is that I am not sure how to go about assigning an object to...
13
2389
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes. Two sub-classes have the relationship to communicate back and forth through this pointer. The pointer is responsible inside Top class for allocating and deallocating two sub-classes. CMemory class is responsible to allocate and deallocate memory...
15
6631
by: Iced Crow | last post by:
In C# I know that you can use delegates to assing multiple addresses of sub and functions to a delegate and have it fire multiple procedures... How do I do this in VB? I only know of assigning a single method to a delegate in VB.NET. I want to use it as in C#... to fire multiple events. Thanks in advance!
20
7013
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
17
2624
by: Calle Pettersson | last post by:
Coming from writing mostly in Java, I have trouble understanding how to declare a member without initializing it, and do that later... In Java, I would write something like public static void main(String args) { MyType aMember; ... aMember = new MyType(...) ... } However, in C++ this does not seem to work. I declare in class (it's
1
2266
by: weston | last post by:
So, the following apparently works as a method of grafting a method onto an object (using the squarefree JS shell): obj = { x: 1, inc: null } result obj.inc = function () { this.x++ } result function () { this.x++; } obj.inc() obj.x result 2
1
1577
by: matthew.macdonald-wallace | last post by:
Hi all, I'm trying to add functionality to an app written in C# so that a list of people is displayed in a list box on the left hand side and then selected individuals can be added to another list box on the right-hand side. I've got the data from my database into a database reader and I can get it into an arrayList, however I can't get it to do what I want! :)
8
4547
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I have a large class with a lot of member variables. I also have a function in the class that I would like to change ALL Of the member variables. I am trying to assign "this" to the result, but I always get the error message, "Cannot assign to '<this>' because it is read-only." I've been searching on the Internet, and I notice some C# code is violating this rule. Perhaps their code is wrong.
1
1375
by: JohnSmith70 | last post by:
I am storing previously entered values of a,b,c in a vector as you can see below. Later the user has the option to use one the objects from the vector, and assigns the value to the variables, which therefore are entered using the old values. But the problem is the object assigned are meaningless numbers(i.e. 32252355). How can I get the value of one of the old 'a'(eg. a of that particular slot) and assigned to the new 'a'? #include <iostream>...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
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
6780
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
5437
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.