J'ai cette erreur : Fatal error: Uncaught Error: Cannot instantiate abstract class Form…
- User
J'ai cette erreur : Fatal error: Uncaught Error: Cannot instantiate abstract class Form in C:\Users\amael\OneDrive\Bureau\cours\php\tp5\index.php:94 Stack trace: #0 {main} thrown in C:\Users\amael\OneDrive\Bureau\cours\php\tp5\index.php on line 94 j'essaie de lancer un projet php à l'aide de ce fichier :
require 'Classes/Quizz/Autoloader.php'; require_once 'Classes/Provider.php'; Autoloader::register(); $provider = new Provider('data/data.json'); $data = $provider->getData(); $question_total = 0; $question_correct = 0; $score_total = 0; $score_correct = 0; function question_text($q) { echo ($q["text"] . "<br><input type='text' name='$q[name]'><br>"); } function answer_text($q, $v) { global $question_correct, $score_total, $score_correct; $score_total += $q["score"]; if (is_null($v)) return; if ($q["answer"] == $v) { $question_correct += 1; $score_correct += $q["score"]; } } function question_radio($q) { $html = $q["text"] . "<br>"; $i = 0; foreach ($q["choices"] as $c) { $i += 1; $html .= "<input type='radio' name='$q[name]' value='$c[value]' id='$q[name]-$i'>"; $html .= "<label for='$q[name]-$i'>$c[text]</label>"; } echo $html; } function answer_radio($q, $v) { global $question_correct, $score_total, $score_correct; $score_total += $q["score"]; if (is_null($v)) return; if ($q["answer"] == $v) { $question_correct += 1; $score_correct += $q["score"]; } } function question_checkbox($q) { $html = $q["text"] . "<br>"; $i = 0; foreach ($q["choices"] as $c) { $i += 1; $html .= "<input type='checkbox' name='$q[name][]' value='$c[value]' id='$q[name]-$i'>"; $html .= "<label for='$q[name]-$i'>$c[text]</label>"; } echo $html; } function answer_checkbox($q, $v) { global $question_correct, $score_total, $score_correct; $score_total += $q["score"]; if (is_null($v)) return; $diff1 = array_diff($q["answer"], $v); $diff2 = array_diff($v, $q["answer"]); if (count($diff1) == 0 && count($diff2) == 0) { $question_correct += 1; $score_correct += $q["score"]; } } $question_handlers = array( "text" => "question_text", "radio" => "question_radio", "checkbox" => "question_checkbox" ); $answer_handlers = array( "text" => "answer_text", "radio" => "answer_radio", "checkbox" => "answer_checkbox" ); if ($_SERVER["REQUEST_METHOD"] == "GET") { require "Action/Form.php"; $form = new Form($data); $form->buildForm(); } else { echo "<br>Nombre de questions : $question_total<br>"; echo "Nombre de bonnes réponses : $question_correct<br>"; echo "Score total : $score_total<br>"; echo "Score obtenu : $score_correct<br>"; } ?> </body> - Assistant
L'erreur que vous rencontrez indique que vous tentez d'instancier une classe abstraite appelée
Form. En PHP, une classe abstraite ne peut pas être instanciée directement - elle est conçue pour être héritée par d'autres classes qui implémentent les méthodes abstraites définies.L'erreur complète est :
Fatal error: Uncaught Error: Cannot instantiate abstract class Form in C:\Users\amael\OneDrive\Bureau\cours\php\tp5\index.php:94 Stack trace: #0 {main} thrown in C:\Users\amael\OneDrive\Bureau\cours\php\tp5\index.php on line 94
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.