473,398 Members | 2,088 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,398 software developers and data experts.

arrays containing class types

I am new to PHP. Can I define an array in PHP 4.3 containing class
types?

ie. (simplified example)

class MyType
{
function MyFunc()
{
$newType = new MyType;
this->$array_MyType[] = $newType;
}
}

I am getting an error "Cannot use [] for reading"

Thanks

Oct 6 '05 #1
5 1492
mungflesh wrote:
I am new to PHP. Can I define an array in PHP 4.3 containing class
types?

ie. (simplified example)

class MyType
{
function MyFunc()
{
$newType = new MyType;
this->$array_MyType[] = $newType;
}
}

I am getting an error "Cannot use [] for reading"


I would check the syntax for "this", if I were you...

--
Oli

Oct 6 '05 #2
yeah sorry - i wrote that off the cuff. the syntax in my script does
contain $this. i'm a C++ dev by proffession and there's no $s tagged
onto variables.

Oct 6 '05 #3
mungflesh wrote:
yeah sorry - i wrote that off the cuff. the syntax in my script does
contain $this.


OK, but have you also removed the "$" in front of array_MyType? i.e.:

$this->array_MyType[] = $newType;

--
Oli

Oct 6 '05 #4
nice one. that's the problem.

thanks for your help.

Oct 6 '05 #5
Oli Filth wrote:
mungflesh wrote:
I am new to PHP. Can I define an array in PHP 4.3 containing class
types?

ie. (simplified example)

class MyType
{
function MyFunc()
{
$newType = new MyType;
this->$array_MyType[] = $newType;
}
}

I am getting an error "Cannot use [] for reading"

I would check the syntax for "this", if I were you...


It should be

$this->array_MyType = array();
$this->array_MyType[] = $newtype;

(Assuming $array_MyType is a class variable)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 6 '05 #6

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

Similar topics

21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
79
by: Me | last post by:
Just a question/observation out of frustration. I read in depth the book by Peter Van Der Linden entitled "Expert C Programming" (Deep C Secrets). In particular the chapters entitled: 4: The...
2
by: JJ Feminella | last post by:
This statement is legal C#: public const string day = "Sunday"; but this statement is not: public const string days = new string { "Sun", "Mon", "Tue" }; The C# Programmer's Reference...
33
by: Peter Seaman | last post by:
I understand that structures are value types and arrays and classes are reference types. But what about arrays as members of structures i.e. as in C struct x { int n; int a; }
3
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
8
by: Spoon | last post by:
Hello, Could someone explain why the following code is illegal? (I'm trying to use a list of (C-style) arrays.) #include <list> typedef std::list < int foo_t; int main() { int v = { 12, 34...
127
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
0
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...
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
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,...
0
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...

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.