'SV2024001', 'name' => 'Nguyễn Minh Khôi', 'age' => 20], ['id' => 'SV2024002', 'name' => 'Trần Hoàng Yến', 'age' => 19], ['id' => 'SV2024003', 'name' => 'Lê Quốc Bảo', 'age' => 21], ]; } $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['reset'])) { unset($_SESSION['lab02_bai08_students']); header('Location: index.php'); exit; } $id = strtoupper(trim($_POST['student_id'] ?? '')); $name = trim($_POST['name'] ?? ''); $age = (int)($_POST['age'] ?? 0); if ($id !== '' && $name !== '' && $age > 0) { $_SESSION['lab02_bai08_students'][] = [ 'id' => $id, 'name' => $name, 'age' => $age ]; $message = "Đã thêm sinh viên {$name} ({$id}) thành công!"; } } // Khởi tạo mảng các đối tượng App\Students\Student $studentObjects = []; foreach ($_SESSION['lab02_bai08_students'] as $row) { $studentObjects[] = new Student($row['id'], $row['name'], (int)$row['age']); } ?>
Namespace App\Students — Lớp Student extends Person được nạp tự động qua autoload.php
App\Students\Student
= count($studentObjects) ?> sinh viên
| # | Mã SV (Student) |
Họ và tên (Kế thừa Person) |
Tuổi (Kế thừa Person) |
Class Namespace |
|---|---|---|---|---|
| = $index + 1 ?> | = htmlspecialchars($st->getStudentID()) ?> | = htmlspecialchars($st->getName()) ?> | = $st->getAge() ?> | = get_class($st) ?> |