#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    61
    Rep Power
    12

    Class members in PHP extensions


    I have made my first extension for PHP recently, and faced this challange: Make the extension act as a PHP class, and have some handles or private members in it, that can be stored acress calls to methods of my class.


    I have solved it by creating a handle and saving it as a resource, and then using update_hash_index to store the resource zval in object's property table at index 0.

    This soulution works, but since it is necessary to first fetch the resource handle from object properties, then fetch the actual handle from resource list, this approach seems inefficient. The overhead of fetching is considerable when methods are called inside a loop.

    I am looking for a better way to do this, but I am not very familiar with developing PHP extensions and I was unable to find much documentation. I hope that somebody can guide me in the right direction.
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Can't say that I can offer much help on this but I can tell you a good place to look. There is an existing class in php that you could use for a reference. I would look up in the php source code for the dir class.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Is this a program for a class?

    There's someone else asking a very similar question in the current thread:

    "Sending an object refrence?"

    You might see if that thread gives you some ideas.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    61
    Rep Power
    12
    Onslaught <- is "dir" an extension to PHP? I didn't seem to have any luck finding it in the PHP source distro.

    7stud <- I have read the thread, you refer to, but it seems to be concearned with passing objects in C/C++ rather than creating/storing/retrieving members in PHP classes, that are implemented as extensions.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    operator smooth,

    The word "dir" is a link in Onslaught's post. Just click on it.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    61
    Rep Power
    12
    I did :)
  12. #7
  13. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    It isn't an extension, it would be in the bulk of the main source code.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    61
    Rep Power
    12
    Oh... well, then I don't think I can use it, becouse my extension is a loadable module, it is not inserted into the core of PHP...
  16. #9
  17. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    You should still be able to use the source as a reference as to how to handle the class members, but this is just a suggestions.

IMN logo majestic logo threadwatch logo seochat tools logo