views:

134

answers:

4

Python has ctypes to access libraries. In PHP you write extensions for everything. Popular extensions like the one for libgd are available almost everywhere.

Is there any extension which works like Python's ctypes, letting you access libraries without the need to write an PHP extension?

A: 

I don't think there is such a thing : in PHP, the "standard" way of using a library is by writting a wrapper arround it, that exports the functions of the library to PHP.

(But maybe an extension could be written to do just what ctypes does ? -- Not sure, but maybe ^^ )

Pascal MARTIN
It's definately possible, though I see some pretty huge security issues here. Beginner PHP programmers aren't known to be able to control all aspects of their app (and neither does half of the experienced ones). What if someone manages to run some injected code that uses ctypes in PHP -- that includes being able to load external libraries, otherwise what's the point. All of PHP's security model (if there ever was such a thing) would be compromised.
Tor Valamo
+1  A: 

You're looking for ffi.

Ignacio Vazquez-Abrams
Last release is 0.3 (alpha) 2004-01-20.
stesch
+1  A: 

There is a PHP extension (irony?) called ffi. FFI stands for Foreign Function Interface, which is the generic term for when a language calls libraries written in another language.

Anthony
+1  A: 

I don't know of any way. But you could let SWIG build an extension for the library you want.

Not exactly what I had in mind. But at least I don't have to write the extension on my own.
stesch