Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69818 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13503 invoked from network); 23 Oct 2013 20:19:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Oct 2013 20:19:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:33817] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/C7-10840-85F28625 for ; Wed, 23 Oct 2013 16:19:37 -0400 Received: from [192.168.2.20] (ppp-88-217-87-77.dynamic.mnet-online.de [88.217.87.77]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id A9651408E9; Wed, 23 Oct 2013 22:19:48 +0200 (CEST) To: Kevin Ingwersen Cc: internals@lists.php.net In-Reply-To: <7AB4C690-44A7-4A93-9026-F5E735716E0F@googlemail.com> References: <7AB4C690-44A7-4A93-9026-F5E735716E0F@googlemail.com> Content-Type: text/plain; charset="UTF-8" Date: Wed, 23 Oct 2013 22:19:20 +0200 Message-ID: <1382559560.8840.19.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PHP and Objective-C From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) 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