Re: PHP and Objective-C

From: Date: Wed, 23 Oct 2013 20:19:20 +0000
Subject: Re: PHP and Objective-C
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi,

On Wed, 2013-10-23 at 20:20 +0200, Kevin Ingwersen wrote:

> I have learned, that Objective-C is, like C++, a layer ontop of C.

C++ had been a layer on top of C but is a completely different language.
While it is mostly (but not fully) backwards compatible with C. I assume
this is true for ojective-C, too

>  Furthermore, I saw that there was am "embed" SAPI, yet I couldn't
> find any way to fully integrate PHP into a binary that had non-Zend
> code inside; there is only a book. And due to my visual impairment, I
> am unable to read said book.

You will always need the zend-engine, if you want to do anything
useful. 


> So I came up with a few questions:
> 
> 	- How could one integrate PHP into a C/C++ programm?
> The reason I ask is because, I want to see how far I could integrate
> PHP into an Objective-C program.

For embedded compile PHP --enable-embed and then look at the
sapi/embed/php_embed.c header. A minimal C program which can run a
simple PHP script might look like this:

#include "sapi/embed/php_embed.h"

int main (int argc, char *argv[]) {
   PHP_EMBED_START_BLOCK(argc, argv)
   zend_eval_string("echo 'Hello world';", NULL, "(emedded eval)"
TSRMLS_CC);
   PHP_EMBED_END_BLOCK()
}

If PHP+embedded sapi was compiled and installed this program can be
compiled in some way like this:

   $(CC) -otest -L/usr/local -I/usr/local/include/php -lphp test.c

(untested)

How to call c APIs from Objective-C you have to find in Objective-C
documentation.

> 	- When integrating, how could I expose Objective-C functions to PHP's
> "C-Scope"?
>
> The Zend 2 API is very poorly documented; basic things like
> reading/writing to and from objects is documented so poorly, that I
> had to read a ~100 page long slide share. But yet, I thought that the
> only way to expose stuff like Objective-C functions, or even Classes,
> to PHP would be to add a PHP-Extension-like structure, so that once
> the Objective-C programm was initialized, it would use the Zend API to
> expose things to PHP.
> 
Yes.

> My goal is to enable access to at least the GUI functions of Cocoa,
> which can be reached thru Objective-C. Using this method, I wanted to
> create a new kind of framework, and combine it with my previous
> project of pulling PHP files into one. I think it already made a clue
> in your head if you are able to understand my - sadly - weird english.

Mind that their are issues - when doing this you have to understand
objective-C's and cocoa's garbage collection and see how that fits into
PHP for not freeing things you still neeed etc. so deep understanding of
Cocoa&Co is a primary requirement.

I now way too little about that Mac stuff but see that side as the
bigger problem one has to master. After that it's mostly a question of
available time to write the actual stuff ...

johannes




Thread (3 messages)

« previous php.internals (#69818) next »