I am trying to write some code that access images from S3 on AWS using inheritance. I have gotten the code to work in one long file but it gets a bit unwieldy.
I am new to PHP inheritance so I'm not sure what's going wrong here. I have a class called PersonPics
that inherits from myAWS
. These are referenced in a third file downloadImages
.
I've traced the error to be related to the $s3Client
variable.
When I have the code written in the myAWS
class written as$this->s3Client->getIterator(...)
I get an error calling member function on null error. If I change it to $this->$s3Client->getIterator(...)
I get a undefined variable s3ClientError
despite it being defined in the constructor.
What am I doing wrong?
myAWS.php
class myAWS{
private $s3Client;
private $bucket = 'my-bucket';
function __construct() {
$S3Client = S3Client::factory(array( ... )); //credentials inserted
}
function getImages($name){
$img_iter = $this->s3Client->getIterator('ListObjects', array(
'Bucket' => $bucket,
'Prefix' => $name . '/img',
));
// ... more
return img_arr;
}
}
PersonPics.php
error_reporting(E_ALL);
ini_set("display_errors","On");
require_once __DIR__ . '/myAWS.php';
class PersonPics extends myAWS {
public $name;
function __construct($name){
$this->$name = $name;
}
function getImages(){
$pic_arr = parent::getImages($this->name);
// more functionality to be added later using $pic_arr
}
}
downloadImages.php
require_once __DIR__ . '/myAWS.php';
require_once __DIR__ . '/PersonPics.php';
$name = $_GET["name"];
$aws = new myAWS();
$lookupPerson = new PersonPics($name);
$images = $lookupPerson->getImages();