No $ on description here; you are getting the description property on the Task object
<?= $task->description; ?>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, im new to PHP and Im going through the PHP Practitioner 101 class, Im up to lesson 12 - Classes. So far everything makes so much sense and Jeffrey explains things so easy, but Im stuck and I cannot figure out where Im going wrong. Im getting these errors:
Warning: Undefined variable $description in C:\xampp\htdocs\phptest\index.view.php on line 12
Warning: Undefined property: Task::$ in C:\xampp\htdocs\phptest\index.view.php on line 12
Warning: Undefined variable $description in C:\xampp\htdocs\phptest\index.view.php on line 12
Warning: Undefined property: Task::$ in C:\xampp\htdocs\phptest\index.view.php on line 12
Warning: Undefined variable $description in C:\xampp\htdocs\phptest\index.view.php on line 12
Warning: Undefined property: Task::$ in C:\xampp\htdocs\phptest\index.view.php on line 12
Here are my 2 pages of code:
index.php
<?php
class Task {
public $description;
public $completed = false;
public function __construct($description)
{
$this->description = $description;
}
public function complete()
{
$this->completed = true;
}
public function isComplete()
{
return $this->completed;
}
}
$tasks = [
new Task('Go to store'),
new Task('Pick up milk'),
new Task('Pay for milk')
];
require 'index.view.php';
index.view.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Test</title>
</head>
<body>
<div>
<ul>
<?php foreach ($tasks as $task) : ?>
<li><?= $task->$description; ?></li>
<?php endforeach; ?>
</ul>
</div>
</body>
</html>
Hope you can help, thanks.
No $ on description here; you are getting the description property on the Task object
<?= $task->description; ?>
Please or to participate in this conversation.