I have 2 classes, one have 2 variables, and the other have an array who will take theses 2 variables to make a list of a list (I guess, maybe it won't work) but here my problem:
ErrorException array_push() expects parameter 1 to be array, null given
<?php
namespace App\Libraries;
class Caddie
{
public $commandeListe = [];
public function add(string $produit, int $quantite)
{
$ligne = [$produit,$quantite];
array_push($commandeListe,$ligne); //the error is here
}
public function getAll()
{
return $this->commandeListe;
}
};
?>
I'm not sure if the other code is useful but here it is
<?php
namespace App\Libraries;
class Ligne
{
public string $produit;
public int $quantite;
public function __construct($produit, $quantite)
{
$this->produit = $produit;
$this->quantite = $quantite;
}
public function getProduit()
{
return $this->produit;
}
public function getQuantite()
{
return $this->quantite;
}
}
?>
I think the Caddie class don't understand $commandeListe but I don't understand why.
I use codeigniter but I don't think it as an influence on this problem
It's the first time that I ask a question so, sorry if I didn't use the website properly