SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31

Thread: google web API

  1. #26
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So outside of performance, there's no real advantage to having data stored in an object rather than an array? Just wondering why it is Google pass objects in the first place, whether it allows you to process their data more effectively or something.

  2. #27
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is it google, or the SOAP client that is defining things as objects? it maybe just the PEAR SOAP client returning data sets as objects ( a poor way to do it IMO, array's being my choice )
    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));

  3. #28
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In a way, using objects instead of arrays makes more sense. Traditionally (in strongly typed languages), arrays are used to store elements that all have the same type. In PHP this isn't necessary, as you can do this:

    PHP Code:
    $list = array(
        
    'items' => array(123456),
        
    'name'  => 'Integer List',
        
    'size'  => 6
    ); 
    In other words, you can define entirely new datatructures using just arrays. The above structure is an array with only 3 elements, but each element is of a different type. If you don't know the array you're working with well, you can't know anything about the elements and their respective types. Objects make much more sense in that case (especially because you can then hide private data). An object always has a type (its class) and the type implicitly defines what kind of structure it has. This is much more logical, and safer as well.

    I do use arrays like I portrayed here - they can be very convenient at times - but always locally (to a function or to a class). Some class may store an array with some specialized datastructure, but only that class itself can have access to the array. Passing arrays like these around all over the code is dangerous, I think.

    Vincent

  4. #29
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have a point, but there is still hardly a difference between arrays and (eg.) stdClass used just to store data ( excluding the obvious ), so its just a matter of taste, and how you ( or I ) think
    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));

  5. #30
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is completely true. I don't like passing around arrays with data structures because that means other code can access private data directly. However, the fact that PHP doesn't even have private data members in classes and that it's even possible to assign new data members to an object from outside of that object completely negate the advantages of using classes over arrays.

    I mean, this:
    PHP Code:
    $object = new StdClass();
    // $object is an instance of class StdClass, having no
    // data members at all, and no methods either.
    $object->name 'foo';
    // Suddenly $object has a new member variable! 
    ...should be illegal!

    It's all a matter of opinion, really

  6. #31
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, yes it should be illegal.
    There should also be private data members and methods as well
    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •