Kyle Kirby
February 9, 2012
Hello everyone (or just hello Kyle, since I don't think anyone else
is reading this).
Personal project development has been pretty slow lately; I've been
pretty busy at work. However, these past two days I have been able
to spend some time on my own interests (yay!).
I was sitting at my desk at work when I thought to myself how I
wish making beautiful code was easier. You have the hassle of writting
propery PHPDoc, getter/setters, proper property naming and worrying
about the design of all your classes. It takes so much time to do this
and to worry wether or not you'll need to go back and modify something
later.
Then I thought, how cool would it be to have Objective-C's @synthesize
on PHP. And having the ability to define parameters in a simple
form much like that of C++.
After stumbling around in my mind, I wondered how feasable it would be
to take an Objective-C/C++ style @interface and convert it to PHP
with all PHPDoc, getter/setters, properties, the works.
A few hours later, I present to you the pseudo Objective-C code and
the resulting PHP code:
The code you see is real and was generated by my script. My script
is able to understand protected, private, and public
method/properties. Static and instance methods/properties.
Methods that have referenced arguments, and return references.
By default, a property defined will have synthesized methods
(getters and setters). The access level of the synthesized methods
will be in the same as that of the property. You'll notice things
in my psuedo code like "(r+)" or "(r)". This defines what can be done
in a public scope. r+ means that get and set will be public regardless
of the scope of the property. r means only get will be public, and w
means only set will be public.
When defining a method, you set it to static using a '+' and instance
using '-', just like Objective-C. You define arguments of the method
by appending a colin and a list of arguments. eg:
+ (void) doSomething: (int)someNumber, (array)someArray;
When a method has an argument, PHP doesn't automatically type check
primatives, only objects. To solve for this, the script will
apply type checking to your method.
I plan to add a lot more on to this script; things like abstract
classes/functions, interface methods, and implements/extends syntax.
Once done, I plan to share this script via DonationWare on a website.
You can pick your price on it, or if you don't have the money to spare
you can use it for free.
Until next time!