SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: PHP objects

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2000
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I was working with objects within PHP, are there Collections and interfaces to use with the object. (an array of objects)

    Thanks

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can make an array of objects, yes. Is that what you wanted to know?
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2000
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know about an array of Objects, I am assuming that you can not have a collection of objects though. When you make a collection of objects (It is like an array, but you have methods to move forward in the array, move back, remove them, AND you can have mutiple types of objects within the Collection, it doesn't have to be an array of 1 type of an object, it can be multiple types of Objects within an array.

    Thanks,

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would not be suprised if someone has written some container classes for PHP.

    As well providing methods to add, pop, and traverse the collection, in C++ they are vital because *arrays are evil* when used as a container for objects! This is because C++ arrays can only store one type of object. Now if the array is declared to be of type Base (and class Derived inherits class Base) C++ will let you store an object of Derived in an array of type Base (because an object of type Derived *is* also an object of type Base). However, the results may not be pleasant - program corruption - because class Derived will probably take up more bytes than class Base.

    I'm curious as to how PHP being loosely typed affects what you can store into an array. Does PHP suffer from the same problem I described for C++? Perhaps PHPs implimentation of arrays is actually an array of pointers to the objects it contains? Curious

  5. #5
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couple things I'm wondering about OOP in PHP:
    I know we can extend class, but I'm not sure if you can implement an interface!

    Collection, Store,... are just ADTs, so you could just implement the methods. And if you're asking if there is some pre-implemented class then I don't know!
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


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
  •