March 8th, 2003, 10:04 AM
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.
March 8th, 2003, 04:14 PM
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.
March 8th, 2003, 09:16 PM
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.
March 10th, 2003, 04:36 AM
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.
March 10th, 2003, 04:40 AM
The word "dir" is a link in Onslaught's post. Just click on it.
March 10th, 2003, 04:42 AM
March 10th, 2003, 09:04 AM
It isn't an extension, it would be in the bulk of the main source code.
March 10th, 2003, 10:14 AM
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...
March 10th, 2003, 10:32 AM
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.