2013-05-04 7 views
1

에 대한 정보를 표시하려면 ListActivity에서 getCurrent() 함수가 반환되어야합니다. 여기비 객체에서 멤버 함수 호출

Fatal error: Call to a member function getIdentifiant() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/site/prototype/administration.php on line 34

행 34 : : 나는 그것을 할 때 , 내가 페이지 상단에이 오류 메시지가, 내가 클래스에서 필요한 정보를 완벽하게 작동하지만,

while($listActivities->next()) 
    { 
    $current = new Activity(); 
    $current = $listActivities->getCurrent(); 
    echo $current->getId(); // line 34 
    } 

그리고 이것은 Activity 객체를 반환하는 getCurrent() 함수입니다.

public function getCurrent() 
    { 
    if(isset($this->activities[$this->current])) 
     return $this->activities[$this->current]; 
    } 

내가 원하는 개체를 반환하기 때문에 왜이 문제가 있는지 이해할 수 없습니다. 제발 이해해주세요. 감사.

+2

그리고 isset이 실패 할 때 getCurrent()가 반환하는 것은 무엇입니까? 'NULL'? 이것은 대상이 아닙니다. – bwoebi

+0

@bwoebi 페이지의 활동에 대한 정보를 볼 수 있기 때문에 결과를 반환합니다. 그것은 null을 반환하지 않습니다. 답장을 보내 주셔서 감사합니다. – R00t

+0

에코 전에'var_dump()''$ current'을 시도하십시오 ... – bwoebi

답변

0
echo $current->getId(); // line 34 
Fatal error: Call to a member function getIdentifiant() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/site/prototype/administration.php on line 34 

오류가 $ current가 개체가 아니라고 말하면 페이지에서 보았을 것으로 생각됩니다. 현재는 개체가 아닙니다. null는 아니지만, 배열이나 객체가 아닌 것도 될 수 있습니다. 또한

:

$current = new Activity(); 
$current = $listActivities->getCurrent(); 

정말 나에게 의미가되지 않습니다.

사용

var_dump($listActivities->getCurrent()); 

는 정확히 반환과 신뢰 오류가 무슨 말을 무엇을 참조하십시오.

편집 : 올바른 PHP 스크립트를 실제로 보지 못할 수도 있습니다. 코드에 "getId"라고 말하면서 오류는 "getIdentifiant"라고 말합니다. 올바른 코드를보고 올바른 페이지를 새로 고쳐야합니다.

+0

답장을 보내 주셔서 감사합니다! 문제가 있다고 생각해서'$ current = new Activity'라고 썼습니다. 하지만 getCurrect()가' 'object (Activity) # 7 (4) {' "id": "Activity": private} => string (3) "을 반환하는 것 같아요."fir ... blablabla .. .} ** NULL ** ''. 목록의 마지막 개체가 null 인 것 같습니다. 맞습니까? – R00t

0

먼저

(아마도 constercture에서) $current = new Activity();$this->current을 설정하고 또한 !isset($this->activities[$this->current])

하면, 또 다른 변수

에 저장해야합니다 당신은 당신의 Activity 객체를 분실 $current = $listActivities->getCurrent() 사용하는 경우 경우는 false를 돌려

여기에 새 코드 :

while($listActivities->next()) 
    { 
    $current = new Activity(); 
    if( $listActivities->getCurrent()) 
     echo $current->getId(); // line 34 
    } 


    public function getCurrent() 
    { 
    if(isset($this->activities[$this->current])) 
     return $this->activities[$this->current]; 
    return false; 
    } 
+0

니스! 그것은 효과가 있었다. 사실, 함수'getCurrent()'는 목록의 마지막 객체에 대해 항상 'null'을 반환했습니다. 따라서 실제 문제는'while ($ listActivities-> next())'입니다. 실제 마지막 객체 (또는 null)를 호출해서는 안됩니다. 하지만 감사합니다, 당신의 도움은 많이 감사합니다 :) – R00t

+0

@ R00t 나는 이것을 위해 행복합니다 :) 행운을 빌어 요 – Cooper

관련 문제