Im a c# programmer and I’m learning arrays and classes in php. I’m trying to make an array list that contains objects of class document. At the end I want to print each object with its attributes. Here is my code.
Class Document
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;
}
}
Thus is my code calling the class.
$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**
}
There’s a typo:
should be