<?php
use Alura\Pdo\Domain\Model\Student;
require_once 'vendor/autoload.php';
$caminhoBanco = __DIR__ . '/banco.sqlite';
$pdo = new PDO('sqlite: . $caminhoBanco');
$statement = $pdo->query('SELECT * FROM studdents;');
$studentDataList = $statement->fetchAll(PDO::FETCH_ASSOC); // método de consulta padrão
$studentList = [];
// fazendo aqui um tipo de buffer pegando so o que precisa e trazendo para objetos
foreach ($studentDataList as $studentData) {
$studentList[] = new Student(
$studentData['id'],
$studentData['name'],
new \DateTimeImmutable($studentData['birth_date'])
);
}
var_dump
D:\PUCPR\Fundamentos_programação_web_1\PHP\php-8.1.12-nts-Win32-vs16-x64\php.exe D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\lista-alunos.php
Deprecated: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\lista-alunos.php on line 20
Fatal error: Uncaught TypeError: Alura\Pdo\Domain\Model\Student::__construct(): Argument #2 ($name) must be of type string, null given, called in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\lista-alunos.php on line 20 and defined in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\src\Domain\Model\Student.php:11
Stack trace:
#0 D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\lista-alunos.php(20): Alura\Pdo\Domain\Model\Student->__construct(3, NULL, Object(DateTime))
#1 {main}
thrown in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\src\Domain\Model\Student.php on line 11
PHP Deprecated: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\lista-alunos.php on line 20
PHP Fatal error: Uncaught TypeError: Alura\Pdo\Domain\Model\Student::__construct(): Argument #2 ($name) must be of type string, null given, called in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\lista-alunos.php on line 20 and defined in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\src\Domain\Model\Student.php:11
Stack trace:
#0 D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\lista-alunos.php(20): Alura\Pdo\Domain\Model\Student->__construct(3, NULL, Object(DateTime))
#1 {main}
thrown in D:\PUCPR\Fundamentos_programação_web_1\PHP_PDO\php-pdo-projeto-inicial\src\Domain\Model\Student.php on line 11
Process finished with exit code 255