Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2006, 07:52 AM
Registered User
 
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assoc. Array of Objects

Hi,

I have looked around and I cant find a good way to do this.
The problem is that I store my objects in an associative array (name=>object)
but when I try to access the objects later ,like so;
 $tmpObj = $array[$name];
 $tmpObj->method($whatever);
it says $tmpObj isnt a method
Any help would be appreciated

Thanks in advance.

 
Old June 19th, 2006, 11:38 AM
Authorized User
 
Join Date: May 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to guillermo
Default

Quote:
quote:Originally posted by hmmm
 Hi,

I have looked around and I cant find a good way to do this.
The problem is that I store my objects in an associative array (name=>object)
but when I try to access the objects later ,like so;
 $tmpObj = $array[$name];
 $tmpObj->method($whatever);
it says $tmpObj isnt a method
Any help would be appreciated

Thanks in advance.

I'm confused. Are you sure the error is saying that $tmpObj isn't a method? And what do you mean when you say you store your objects in an associate array? Could you post an example of the code you're using?

if $tmpObj is in fact an object, and you want to access an attribute of that object, you do it this way:

    $tmpObj->attribute_name

If you want to access a method, you do it this way:

    $tmpObj->method_name()

Arrays are not objects.
http://us3.php.net/manual/en/language.oop.php
http://us3.php.net/manual/en/language.oop5.php






Similar Threads
Thread Thread Starter Forum Replies Last Post
array of arrays-objects joker Java Basics 1 February 11th, 2007 09:12 PM
How access fields of objects stored in Array List rfinks VB How-To 2 July 11th, 2006 06:00 PM
passing jagged array of objects nutrino Beginning VB 6 0 January 27th, 2006 11:58 AM
Dynamically Creating Objects of Array of Classes dinkarsinha General .NET 0 January 28th, 2005 06:22 AM
Login Failed: Not assoc. w/ Trusted Connection xgbnow Pro VB Databases 4 March 4th, 2004 11:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.