8710 sujets

Développement web côté serveur, CMS

Pourquoi le constructeur de la classe ci-dessous, qui fonctionne correctement en php 7.4, ne fonctionne-t-il plus en php 8 ?

class monoTable
{
public $tbPrincipal;
public $tbMono;
public $champNum;
public $champAlpha;
public $champClePrincipale;
public $champAlphaPrincipal;

public function monoTable ($tablePrincipale,$tableMono)
{
$this->tbPrincipal = $tablePrincipale;
$this->tbMono = $tableMono;
$res = requete ("SELECT * FROM $tableMono");
$this->champNum = $res->fetch_field_direct (0)->name;
$this->champAlpha = $res->fetch_field_direct (1)->name;
$res = requete ("SELECT * FROM $this->tbPrincipal");
$this->champClePrincipale = $res->fetch_field_direct (0)->name;
$this->champAlphaPrincipal = $res->fetch_field_direct (1)->name;
}
}

la fonction requete :
function requete ($sql)
{
global $mysqli;

if (!$res = $mysqli->query ($sql))
{
echo "<p>";
echo $mysqli->error;
exit;
}
return $res;
}
après appel à connection à la base de données.
Toutes les variables sont vides !!
Merci de vous pencher sur ce surprenant problème !!
Modérateur
Hello,

__construct()


ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL);

Modifié par niuxe (03 Jun 2022 - 01:35)
Meilleure solution