So I'm trying to learn phpOOP after stopping programming for a few years, so I'm a bit rusty.
Anyway, I have a class blogEntry so I can display blog entries that have been cleaned with the function cleanForDisplay by echo'ing $blogEntry->article for example. But I am receiving no errors, and the variable is not being displayed.
Thanks
class blogEntry
{
var $headline;
var $author;
var $date;
var $image;
var $imagecaption;
var $article;
public function __contruct()
{
$this->headline = cleanForDisplay($row['headline']);
$this->author = cleanForDisplay($row['postedby']);
$this->imagecaption = cleanForDisplay($row['imagecaption']);
$this->article = cleanForDisplay($row['article']);
$this->image = $row['image'];
$this->date = $row['date'];
}
}
You have a typo, the magic method is
__construct()
and you are not receiving any error because the constructor is not mandatory in PHP.Also, the
$row
variable is not defined, so you fields will be null even with the constructor.Your method is spelt incorrectly. It should read
__construct()
.Secondly, you are not passing in any parameters to the method, and thus,
$row
is undefined.Consider the following:
$row
is passed in as the parameter, and therefore, the variables you are trying to set will be defined.The
blogEntry
class can be initialized as follows: