2011-11-20 9 views
-1

Im C# 프로그래머이고 PHP의 배열과 클래스를 배우고 있습니다. 클래스 문서의 개체가 들어있는 배열 목록을 만들려고합니다. 마지막으로 각 객체의 특성을 인쇄하려고합니다. 여기 내 코드가있다.배열에 클래스 객체 추가

클래스 문서

class Document { 
    public $id; 
    public $filename; 
    public $filetype; 
    public $filesize; 
    public $datecreated; 
    public $datemodified; 

    public function __construct($id, $filename, $filetype, $filesize, $datecreated, $datemodified) { 
    $this->id = $id; 
    $this->filename = $filename; 
    $this->filetype = $filetype; 
    $this->filesize = $filesize; 
    $this->datecreated = $datecreated; 
    $this->datemodified = $datemodified; 
    } 
} 

따라서 클래스를 호출 내 코드입니다.

$documents = glob("C:/xampp/htdocs/researchPortal/document_repository/student/{*.doc,*.docx,*.png}", GLOB_BRACE); 

$docArray = array(); 

//print each file name 
foreach($documents as $doc) 
{ 
$document = new Document(time(),basename($doc),substr($doc, -3),(filesize($doc)/1024),(filesize($doc)/1024)." KB",date("F d Y H:i:s.",filectime($doc)),date("F d Y H:i:s.",filemtime($doc))); 
array_push($docArray,$document); 
} 

foreach($docArray as $file) { 

echo $file; //**ERROR ON THIS LINE** 
     } 

답변

1

가 오타입니다 :

array_push($docAray,$document); 

는해야

array_push($docArray,$document); 
1

당신은 17

0

$docAray 오타 인 줄 $docAray$docArray 철자. $docArray이 귀하의 배열입니다. 오류가 발생한 행에서 누락 된 r을보십시오.