Re: [PHP] Programming general question

2009-01-27 Thread Edmund Hertle
2009/1/28 Terion Miller webdev.ter...@gmail.com

 I googled this and didn't find an answer 
 my question is how do you know when to use an object or array

 would an object just be 1 instance, and array is several things together (
 I
 know infantile coder language I use..but I'm a baby still in this)

 Can someone explain objects and arrays in plain speak for me?
 Thanks
 Happy Coding


Hey,

Arrays: A structure to store data
Example:
$example = array(value1, value2, value3);
echo $example[0]; // echos value1
echo $example[2]; // echos value3

Object: Something totally diffrent. A object is an instance of a class.
Contains variables and methods.

I don't know how you thought of using arrays or objects for the same
problem? Can you give an example?

Try this for arrays: http://de2.php.net/manual/en/language.types.array.php
You should look for object-oriented programming to understand what an
object is
Then you will get help here:
http://de2.php.net/manual/en/language.oop5.basic.php

-eddy


Re: [PHP] Programming general question

2009-01-27 Thread Robert Cummings
On Wed, 2009-01-28 at 01:07 +0100, Edmund Hertle wrote:
 2009/1/28 Terion Miller webdev.ter...@gmail.com
 
  I googled this and didn't find an answer 
  my question is how do you know when to use an object or array
 
  would an object just be 1 instance, and array is several things together (
  I
  know infantile coder language I use..but I'm a baby still in this)
 
  Can someone explain objects and arrays in plain speak for me?
  Thanks
  Happy Coding
 
 
 Hey,
 
 Arrays: A structure to store data
 Example:
 $example = array(value1, value2, value3);
 echo $example[0]; // echos value1
 echo $example[2]; // echos value3
 
 Object: Something totally diffrent. A object is an instance of a class.
 Contains variables and methods.
 
 I don't know how you thought of using arrays or objects for the same
 problem? Can you give an example?

An array's functionality can be implemented as a Class with specific
array instances being Objects. This allows the array to be used in
polymorphic contexts and to be extended by subclasses. The same can be
said for any primitive datatype.

Personally, I haven't seen a need to use an Array class in PHP. That's
not to say it doesn't have a purpose, but I lean towards primitives when
possible for efficiency.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Programming general question

2009-01-27 Thread Nathan Rixham

Robert Cummings wrote:

On Wed, 2009-01-28 at 01:07 +0100, Edmund Hertle wrote:

2009/1/28 Terion Miller webdev.ter...@gmail.com


I googled this and didn't find an answer 
my question is how do you know when to use an object or array

would an object just be 1 instance, and array is several things together (
I
know infantile coder language I use..but I'm a baby still in this)

Can someone explain objects and arrays in plain speak for me?
Thanks
Happy Coding


Hey,

Arrays: A structure to store data
Example:
$example = array(value1, value2, value3);
echo $example[0]; // echos value1
echo $example[2]; // echos value3

Object: Something totally diffrent. A object is an instance of a class.
Contains variables and methods.

I don't know how you thought of using arrays or objects for the same
problem? Can you give an example?


An array's functionality can be implemented as a Class with specific
array instances being Objects. This allows the array to be used in
polymorphic contexts and to be extended by subclasses. The same can be
said for any primitive datatype.

Personally, I haven't seen a need to use an Array class in PHP. That's
not to say it doesn't have a purpose, but I lean towards primitives when
possible for efficiency.

Cheers,
Rob.


ahh i said the same until recently, and it's actually prompted me to 
start making some generic container classes with array accessors.


simple example being, I want an array which can't have duplicates and 
doesn't have any kind of ordered indexing, just an array or container i 
can throw objects in and trust that i won't have any dups. Another 
example is if you want an array of objects which can only be of 
class/interface type x




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Programming general question

2009-01-27 Thread Paul M Foster
On Tue, Jan 27, 2009 at 05:18:35PM -0600, Terion Miller wrote:

 I googled this and didn't find an answer 
 my question is how do you know when to use an object or array
 
 would an object just be 1 instance, and array is several things together ( I
 know infantile coder language I use..but I'm a baby still in this)
 
 Can someone explain objects and arrays in plain speak for me?

An array is like in math, except that an array in PHP stores anything
you like. It's just a bunch of them together.

An object can also store a bunch of different things, but it also has
methods, which are really just functions. An array won't actually *do*
anything; you have to do things *to* it. An object can actually do stuff
at your direction. Like:

$kitchen-make_coffee('cream', 'sugar');

The object here is $kitchen, and you've told it to use its make_coffee()
method, which does something or another. You can also make those
methods private so that code outside the object can't see them.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php