이제 PHP에서도 Objective-C의 아름다운 문법을! == 특징 == * ObjC의 정신을 이어받아, ObjP 자체는 PHP에 살짝 양념을 친 형태를 띈다. * 즉, Objective-P와 순수 PHP 코드를 혼용해 사용할 수 있다! (Just like we can mix up ObjC and pure C!) * 컴파일 후에는 순수 PHP 코드가 된다. * 개발자의 편의를 돕는 Gin 프레임워크가 동봉될 예정이다. (접두어: GN) == Specification (Draft) == === Class 선언 및 정의 === Objective-J의 경우처럼, 클래스의 선언과 정의를 동시에 한다. (사실 PHP의 구조상, 이럴 수 밖에 없다.) 다만, @implementation만 사용하면 @interface가 외로워하니까, 인스턴스 변수의 선언에는 @interface를 사용하도록 하고, 메소드 선언 및 정의에 @implementation을 사용한다. {{{ // 클래스 선언 및 정의 @interface MyFirstObjPClass : GNObject @private // 요건 비지빌리티 인디케이터. 옵셔널하다. :) 생략하면 기본값으로 @protected 적용. $iStoreSomething; @end @implementation MyFirstObjPClass +(int)tellMeTheTruth { return 42; } - (void) doSomeTaskWithSomething:(int)$localIntegerVar { // some magic happens... } @end // 클래스 사용 $myClass = [MyFirstObjPClass new]; [$myClass doSomeTaskWithSomething:42]; [$myClass release]; }}} ==== 실제 구현 ==== 컴파일 이후, 위 코드는 최종적으로 다음과 같이 변해야 한다. (PHP 5 객체 모델) GNAssert()의 경우, 두 번째 인자로 @"문자열"을 받지만, 결과적으로는 컴파일 이후 GNString으로 변해야 한다. {{{ class MyFirstObjPClass extends GNObject implements GNSomeProtocol { private $iStoreSomething; public static function tellMeTheTruth() { return 42; } public function doSomeTaskWithSomething($localIntegerVar, $_objp_type_check=false) { // (void) if($_objp_type_check===true) { if(is_int($localIntegerVar)===false) GNAssert(false, new GNString('뭔가 이상하지 않아?')); } // some magic happens... } } $myClass =MyFirstObjPClass::new(); // defined in GNObject $myClass->doSomeTaskWithSomething(42, true); // Compiler automatically adds last argument! $myClass->release(); // actually, does nothing unless you overrides it. }}}