2010-01-29 1 views
2

sfWebRequest이 아닌 $request으로 전화하면 치명적인가요, 아니면 경고일까요?PHP의 메소드 시그니처가 반드시 필요합니까? 아니면 사용해야합니까?

class jobActions extends sfActions 
{ 
    public function executeIndex(sfWebRequest $request) 
    { 
    $this->jobeet_job_list = Doctrine::getTable('JobeetJob') 
     ->createQuery('a') 
     ->execute(); 
    } 

    // ... 
} 
+1

class A {} class B extends A {} class C {} function foo(A $obj) {} foo(new A); foo(new B); foo(new C); // will raise an error and terminate script 

? – Gumbo

+0

아직 프레임 워크는 학습하는 데 며칠이 걸릴 것입니다. 그러나 결과에 대해 궁금합니다. – user261527

+1

@unknown : 그러나 클래스 '{} class B {public static function foo (A $ obj) {}} B :: foo (새 A()); B :: foo ("not A"); ' – Gumbo

답변

1

치명적인 오류가 될 수 있습니다. 여기

은 예입니다

class MyObj {} 

function act(MyObj $o) 
{ 
    echo "ok\n"; 
} 

function handle_errors($errno, $str, $file, $line, $context) 
{ 
    echo "Caught error " . $errno . "\n"; 
} 

set_error_handler('handle_errors'); 

act(new stdClass()); 
/* Prints                  
*                    
* Caught error 4096                
* ok                   
*/ 

코드가 오류와 함께 실패합니다 set_error_handler 전화가 아닌 경우 :

Catchable fatal error: Argument 1 passed to act() must be an instance of MyObj, 
instance of stdClass given, called in /home/test/t.php on line 16 and defined in 
/home/test/t.php on line 4 
+0

'recoverable'이란 무엇을 의미합니까? – user261527

+0

당신은 그것을 잡을 수 있습니다. – Thomas

5

TypeHinting in the PHP Manual

$request 만약에 장을 참조하십시오 sfWebRequest 인스턴스가 아닙니다. 또는 하위 클래스 또는interface을 구현하면 메서드는 catchable fatal error을 발생시킵니다. 오류가 처리되지 않으면 스크립트 실행이 종료됩니다.

예 인터페이스

당신이 그것을 시도해 봤어
interface A {} 
class B implements A {} 
class C {} 

function foo(A $obj) {} 

foo(new B); 
foo(new C); // will raise an error and terminate script