473,322 Members | 1,538 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,322 software developers and data experts.

Problem with array of objects

Hi! I have a small problem with array and objects:

$a = new A();
$b = new A();
$c = new A();
$d = new A();
$e = new A();

$ar = array($a, $c, $d);

There is a method inside A, which would need the information, that is
that instance ($this) of A a member of array $ar.

I thought, that this could have been tested easily with

if (in_array($this, $ar)) ...

But it is not working.

Is there any easy solution for this?

Thanks,

H.
Jul 17 '05 #1
3 6029
Hannu Tiitu wrote:
Hi! I have a small problem with array and objects:

$a = new A();
$b = new A();
$c = new A();
$d = new A();
$e = new A();

$ar = array($a, $c, $d);

There is a method inside A, which would need the information, that is
that instance ($this) of A a member of array $ar.

I thought, that this could have been tested easily with

if (in_array($this, $ar)) ...

But it is not working.

Is there any easy solution for this?


If the instances of the class differ in their attributes it would be a way
to write a function like that:

function obj_in_array($needle, $haystack) {
foreach($haystack as $v) {
if($v === $needle) return true;
}
return false;
}

For more information about comparison of objects see:
http://www.php.net/manual/en/languag...rison-php4.php

Regards,
David
Jul 17 '05 #2
David Rybach <da***@rybach.de> wrote...

Thanks a lot for the info! This was very helpful for me! H.
Jul 17 '05 #3
Hannu Tiitu wrote:

Hi! I have a small problem with array and objects:

$a = new A();
$b = new A();
$c = new A();
$d = new A();
$e = new A();

$ar = array($a, $c, $d);

There is a method inside A, which would need the information, that is
that instance ($this) of A a member of array $ar.

I thought, that this could have been tested easily with

if (in_array($this, $ar)) ...

But it is not working.

Is there any easy solution for this?


Is $ar a global? And is it declared as a global in your method of A?

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #4

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

Similar topics

8
by: laniik | last post by:
Hi. I have a problem using STL's built in sort that seems impossible to get around. if i have: -------------------------------- struct object { int val; }
8
by: Lou Pecora | last post by:
Problem: If I inherit an object B from A and use references in B to data in A, arrays of B objects which are pointed to by an A pointer causes "EXC_BAD_ACCESS" errors at the point shown in the...
2
by: Dick Swager | last post by:
The following code is from a solution with a C++ project and a C# project. The C++ project creates a managed array and the C# project tries to use it. But I am having a 'System.ValueType' to...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
14
by: Bryan | last post by:
I am attempting to make a web page more Netscape friendly... <a href="http:www.gordonceilings.com"></a> I have already corrected the table issues in an offline staging site (where I do the...
13
by: sonjaa | last post by:
Hi I'm new to programming in python and I hope that this is the problem. I've created a cellular automata program in python with the numpy array extensions. After each cycle/iteration the...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
3
by: sk.rasheedfarhan | last post by:
Hi , Here I am new user to C#, my problem is I have to use dynamic Array of objects. But I heard C# don't support ptrs (using managed code C# support). In short i initialized objects of 1000...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.