Re: Re: Programming general question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 28, 2009 at 11:07 PM, Terion Miller <webdev.terion@xxxxxxxxx> wrote:
> On Wed, Jan 28, 2009 at 3:54 AM, Ondrej Kulaty <kopyto911@xxxxxxxxx> wrote:
>> Thanks for all the information, I was asking because I inherited thousands
> of lines of code that had used mysql_fetch_object(), yet I kept getting so
> many errors so I starting playing with changing them to mysql_fetch_assoc()
> and things seem to work better, so I was wonder why sometimes data from a db
> field can be used as an object or array, the arrays, objects, classes still
> confuses me..oh add functions to that, is there a hiearchy?
>

If an object is not an ACTUAL class instance, then it's no more than a
syntactic sugar array. For example:

$user = new stdClass(); // General class name, used internally by PHP
$user->username = 'John Doe',
$user->email = 'john_doe@xxxxxxxxxxx';
$user->password = md5('some_hard_or_easy_password_string');
...

is almost typical to:

$user = array();
$user['username'] = 'John Doe';
$user['email'] = 'john_doe@xxxxxxxxxxx';
$user['password'] = md5('some_hard_or_easy_password_string');
...

Many programmers particularly use objects for retrieving database
results because they require less verbose than arrays:

$result->username is just easier and less error-prone than $result['username'].

Using objects as class instances is totally different than using
arrays as many repliers have said. They're usually used, objects that
is, within OOP (Object-Oriented Programming), which relies on the idea
of thinking of programming in resemblance to real-world things
(objects). Thinking in this paradigm is, again, totally different than
traditional procedural programming, and requires a hard shift in the
way you think about programming in general. I suggest consulting the
manual sections on OOP (specially for PHP5), or other basic tutorials
or books on this huge subject.

Regards,
Usamah

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux