FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


array of objects?





Gushe
Hello all! Smile

For some pattern matching I am trying to make in PHP, I would need to make an array of objects, now does anybody here knows if that's possible? Smile

let's say:
Code:

class pattern
{
   public $pattern = Array();
   public $patternScore;

   /*
   Some methods here
   */
}


Would this be valid? :
Code:
$newPattern[0] = new pattern();
$newPattern[1] = new pattern();

echo $newPattern[0]->$patternScore;
var_dump($newPattern[1]->$pattern);



I can not test it yet here, since I am having problems with my xampplite, and I am restricted to NotePad scripting. Laughing

Thanks in Advance,
~ GuShe
jmraker
You should be able to put objects in an array

but $newPattern[0]->$patternScore; would be invalid because of the 2nd $
it should be $newPattern[0]->patternScore;

same with the line below it for the same reason
tocapa
An object is just a variable and arrays can take any kind of variable, no types or whatever.

Of course, I really just wanted to reply to say icon love Gushe.
rvec
tocapa wrote:
An object is just a variable and arrays can take any kind of variable, no types or whatever.

Of course, I really just wanted to reply to say icon love Gushe.

an object isn't a variable :S
an object is a possible value for most variables.
an array is "a data structure consisting of a group of elements that are accessed by indexing"(wikipedia) meaning multiple values can be stored in an array.

btw you're mixing those:
http://en.wikipedia.org/wiki/Singleton_pattern#PHP_5
http://en.wikipedia.org/wiki/Factory_method_pattern
http://en.wikipedia.org/wiki/Object_pool
Gushe
Actually the $ signs weren't even present in my original code. Smile

Thanks anyway guys! Wink

(Made the icon mayself ) Cool
Related topics
(official) Firefox & Thunderbird 1.5 Beta2 Now Available
Fortran Tutorials(77)
[JS] onclick to print out info
Java tutorials
[php] array reference
The 10th planet
how to accept array variable from a form in Perl
Astrology vs. Christianity?
Visual Basic Tutorial - Control Arrays: What, Why and How
Theoretical Scientific Evidence For the Existence of God
how to handle post data as an array
howto: Array ??
PHP Calendar Bug
passing javascript array
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.