Making a resource?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Making a resource?

Post by Eric! »

Is it possible to make a new resource function in PHP? For example can I replace a fsockopen or fopen with a custom resource that does something else with the data passed to it? I can't seem to find much information on this. Perhaps I'm using the wrong terminology?

Should I be looking at building a streamWrapper?
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: Making a resource?

Post by egg82 »

I'm not 100% sure about classes (never tried them myself) but if PHP is anything like C or C++ (which it is) then a class is what you're looking for
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Making a resource?

Post by Eric! »

I don't think resources are the same as classes in php. http://php.net/manual/en/language.types.resource.php

"Special variable"? The example in the manual doesn't help me much.
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: Making a resource?

Post by genix2011 »

hmm... seems like you'd have to code that directly into the Zend engine :)

Seriously, it depends what you want to do exactly, you could perhaps achieve this with the streamWrapper.

Greets.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Making a resource?

Post by Eric! »

I think a resource is a name for an external entry point to a compiled library. So streamwrapper it is.
Post Reply