Coding

Objective-PHP and Moka


Objective-PHP is a port of the Objective-C (or Objective-J ) runtime to PHP. This adds the language features of Objective-C nestled nicely inside the syntax of Objective-C.

Main Repo: http://github.com/stevegeek/moka

Examples: http://github.com/stevegeek/mokaexamples

Released under the LGPL (see COPYING & COPYING.LESSER) Copyright 2009, 2010 Stephen Paul Ierodiaconou

Moka is a port of the Apple Cocoa Frameworks (or Cappuccino ). As PHP is primarily a server side scripting language the frameworks are currently non-UI ones (Foundation).

I created this a way of learning the Objective-C/J languages in as much depth as possible. However, through this process a programming language and set of tools has resulting and as such has been released as Open Source in the hope others too can learn and find use from it. Also since the original goal was to learn I have created this site and as much documentation and tutorials as I could muster so others too could effectively follow this learning path. I hope this complements the skills of the Objective-J Cappuccino programmers, who may program the backend in the well estabilished PHP while still using the syntax and Objects they are so familiar with.

What?

  • A superset of PHP (you can use normal PHP anywhere and as much as you like)
  • Smalltalk 80 / Objective-C object model
  • Lovely Smalltalk square bracket syntax
  • Dynamic dispatch and delegate programming
  • A programming philosophy
  • Features:
    • Objective-PHP & Moka will work happily alongside any PHP Framework
    • Protocols
    • Categories
    • Command line build tools
    • Cross platform (all you need is PHP)

Example Code:

// Test app
@import <Foundation/Foundation.op>
@implementation Test : MKObject
{
    @public     MKString        test1 = "World"     @accessors;
    @protected                  test2 = 12;
    @private    MKDictionary    dic                 @accessors;
}
- (id)init
{
    if ($self = [super init])
    {
        $self->dic = [MKDictionary dictionary];
        [$self->dic setObject:
            [[MKString alloc] initWithString:"Hello"] forKey:"First"];
    }
    return $self;
}
- (void)hello:name1 and:name2
{
    echo $self->test1." ".[$self->dic objectForKey:"First"].
                        " and ".$name1." and ".$name2."\n";
}
+ (String)testclass:variable
{
    return "\nHi from class Method\n".$variable;
}
@end
?>
<p>This is in HTML mode</p>
<?
$instance = [[Test alloc] init];
[$instance hello:"Jane" and:"Bob"];

Why?

  • It was fun and interesting to develop!
  • Ease of development for devs using Objective-C/J and Cocoa/Cappuccino
  • Delegate pattern without extra coding, Objective-C/J like programming
  • Cocoa-like Frameworks (Non UI ones)
  • Ability to message nil (null)
  • Nicer syntax for dynamic dispatch

For years now I have developed for research and as such have been bound to Matlab and C/C++. To put it lightly I am not a fan of these languages. Recently I have become obsessed with Objective-C, however do not develop in it as much as I wish I could. I use PHP a bit and love the speed of development (this is also Matlab’s only saving grace). Thus born of the desire for a web app development language which is fast, easy to learn, and powerful, is this project.

Of course, I am happy to admit it is completely and utterly inspired by Objective-J and Cappuccino and am happy to plug those as much as possible.

How?

Objective-PHP is PHP, a runtime and a preprocessor. The language can either be interpreted at runtime (into PHP) or for deployment and better performance, preprocessed to generate pure PHP.

Source Code

Main Repo: http://github.com/stevegeek/moka

Examples: http://github.com/stevegeek/mokaexamples

Discussion Group

Google Group: http://groups.google.com/group/objective-php


The MVP definition challenge »

Read more • Open-source