Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá Pessoal,
Estou tentando adicionar informações em uma lista, pórem aparece o erro:
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\wamp\www\Trabalho11\Lista_Cliente.php on line 26
Warning: array_slice() expects parameter 1 to be array, null given in C:\wamp\www\Trabalho11\Lista_Cliente.php on line 21
Warning: array_slice() expects parameter 1 to be array, null given in C:\wamp\www\Trabalho11\Lista_Cliente.php on line 22
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\wamp\www\Trabalho11\Lista_Cliente.php on line 26
object(Lista_Cliente)#1 (1) { ["lista":"Lista_Cliente":private]=> NULL }
Está passando valores nulos:
include "Teste.php";
include "Cliente.php";
class Lista_Cliente {
private $lista;
public function _construct(){
$this->lista=array();
}
public function remover($cliente, $pos){
$anterior = array_slice ($lista,0, $pos);
$posterior =array_slice ($lista,$pos +1);
$mix = array_merge($anterior, $posterior);
}
public function add($cliente, $pos){
$antes = array_slice ($this->lista,0, $pos);
$depois = array_slice ($this->lista,$pos);
$novo = array($cliente);
$this->lista = array_merge ($antes, $novo, $depois);
}
}
Teste.php
include "Cliente.php";
include "Lista_Cliente.php";
$lista = new Lista_Cliente();
$cliente1 = new Cliente ("Wellington", 29051987, "Orfanatrófio");
$cliente2 = new Cliente ("João",13101980,"Centro");
$cliente3 = new Cliente ("Paulo", 20021990,"Praia de Belas");
$lista->add ($cliente1,0);
$lista->add ($cliente2,1);
$lista->add ($cliente3,2);
var_dump ($lista);
As funções remover e adicionar não funcionam
Obrigado
Carregando comentários...