FAQ
Hello there.

I have absolutely no real clue where to post this but rather into some sort of development mailing list.

Recently, I started to work on some tool that will compile a lot of PHP scripts into a single file, and may even go further and bundle a PHP binary within to create a sort-of standalone PHP executable. The concept is quite simple, but the including stuff isn't really. But, as I was thinking about this idea, I came across the various ideas of trying to use a GUI with PHP scripts. On windows, that has already been possible. But not on Mac - at least I found no working solution. wxWidgets (as extension, wxPHP) won't compile because it relies on the Carbon framework - which has been discontinued since about at least three major releases. And the extension can't be made to work with Cocoa, as this is Objective-C - and not C/C++.

And here is the keyword, Objective-C.

I have learned, that Objective-C is, like C++, a layer ontop of C. 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.

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.

  - 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.


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.

Once I can expose Objective-C scope into PHP, I would be able to enable GUI's with PHP. Since PHP is very easily understood, it could be a good start for switchers - like me - to understand the other language and API. Now, we can use my code-compiler idea and build all the PHP script into one single, giant file - maybe even use Phar as this offers a great solution for that. The last step is to combine the executable and script, and we would get an actual and valid Mac OS X application - we do not need the compiling part, but it'd be cool ;).


I hope anybody can help me, poke me into the right direction to anything. This is just one idea I have, and something I hope to realize. I taught myself a good amount of c++ by trying to create a wrapper of a C++ class for a PHP extension. So I would try the trick again to learn more about objective-C.

Kind regards,
Kevin Ingwersen

PS: I am from germany, my english may not be very understandable - so please ask if you didn't understand something! :)

Search Discussions

  • Mike Ho at Oct 23, 2013 at 7:04 pm
    Kevin,

    This may seem like a good idea — and it's been attempted several times in the past… if you do a just google for PHP and Objective-C and/or PHP and Cocoa, you'll see some hits for a number of past open source project that attempted to start going down this path, but never really got any traction.

    However, even if those projects did come to fruition, in practice this actually won't help that much.

    At the end of the day, when writing applications in for Mac OS X and/or iOS, a developer will need to learn two things:
      1. the Objective-C language and runtime
      2. the Cocoa or Cocoa Touch API

    As someone who has done a lot of PHP development and who transitioned into iOS development several years ago (and now I am actively developing on both platforms), I can say from personal experience that "#2" is significantly more of a challenge than "#1".

    Ultimately, when looking at #1, it's really just a change in syntax. You're really just using a bunch of "[]" and "." instead of "$" and "->". Honestly, when comparing the language of Objective-C and PHP, other than these syntax differences, there isn't much else that is different. Even memory management is now taken care of you via the runtime's ARC feature. And yes, while I may be oversimplifying things here a bit, once you dig into it I think you'll quickly see what I mean.

    I actually gave a talk about this at php|tek last year: http://www.quasidea.com/talks/iOSDevelopmentPrimerForPHP.pdf

    The steeper learning curve, by far, is #2, and unfortunately, you would still have to learn it even if you were able to wrap all the API calls around a PHP wrapper.

    It's ultimately the reason why there is so much push back against a lot of these language-based wrappers around Cocoa and Cocoa touch, including things like Mono Touch, Flash Builder, and even to a certain extent the hybrid app platforms like PhoneGap or Appcelerator. Regardless of your choice of language, you still need to learn the APIs.

    If you want some free advice from someone who has gone down the path of transitioning from PHP to Objective-C, spend the time to learn Objective-C and the Cocoa [Touch] APIs natively. It will be a much wiser investment of your time and effort than trying to build a wrapper library for it in PHP.

    Just my 2 cents,
    Mike

    On Oct 23, 2013, at 11:20 AM, Kevin Ingwersen wrote:

    Hello there.

    I have absolutely no real clue where to post this but rather into some sort of development mailing list.

    Recently, I started to work on some tool that will compile a lot of PHP scripts into a single file, and may even go further and bundle a PHP binary within to create a sort-of standalone PHP executable. The concept is quite simple, but the including stuff isn't really. But, as I was thinking about this idea, I came across the various ideas of trying to use a GUI with PHP scripts. On windows, that has already been possible. But not on Mac - at least I found no working solution. wxWidgets (as extension, wxPHP) won't compile because it relies on the Carbon framework - which has been discontinued since about at least three major releases. And the extension can't be made to work with Cocoa, as this is Objective-C - and not C/C++.

    And here is the keyword, Objective-C.

    I have learned, that Objective-C is, like C++, a layer ontop of C. 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.

    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.

    - 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.


    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.

    Once I can expose Objective-C scope into PHP, I would be able to enable GUI's with PHP. Since PHP is very easily understood, it could be a good start for switchers - like me - to understand the other language and API. Now, we can use my code-compiler idea and build all the PHP script into one single, giant file - maybe even use Phar as this offers a great solution for that. The last step is to combine the executable and script, and we would get an actual and valid Mac OS X application - we do not need the compiling part, but it'd be cool ;).


    I hope anybody can help me, poke me into the right direction to anything. This is just one idea I have, and something I hope to realize. I taught myself a good amount of c++ by trying to create a wrapper of a C++ class for a PHP extension. So I would try the trick again to learn more about objective-C.

    Kind regards,
    Kevin Ingwersen

    PS: I am from germany, my english may not be very understandable - so please ask if you didn't understand something! :)
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Johannes Schlüter at Oct 23, 2013 at 8:19 pm
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedOct 23, '13 at 6:20p
activeOct 23, '13 at 8:19p
posts3
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase