7

i have an array in php full of "Eventos Calendario" objects, at some point in my script i need to introduce a new object of the same type at position x of this array. this is the code i am using

$EventoLimite = new EventosCalendario(null,$Timestamp, $TipoEvento);                
var_dump($EventoLimite);
array_splice($this->EventosEntrada, $i, 0, $EventoLimite); //
var_dump($this->EventosEntrada[$i]);

And the "Var_Dumps" i am getting are:

object(EventosCalendario)[15]
  public 'FechaHora' => int 1376334000
  public 'FechaHoraOriginal' => null
  public 'Tipo' => string 'Entrada' (length=7)
  public 'Origen' => string 'Insertado' (length=9)
  public 'Subtipo' => null
  public 'ID' => null

int 1376334000

Why is the new slot in the array only getting the value of "FechaHora" property? i need to get the whole object in $this->EventosEntrada[$i]. how can i do that??

4

2 回答 2

16

“替换”参数必须是一个数组本身,所以你应该写

array_splice($this->EventosEntrada, $i, 0, [$EventoLimite]); // note []s
于 2013-09-28T22:15:34.003 回答
0

也许是因为当您引入一个新对象时,您处理的特定文件中只有公共变量和函数可用。我的意思是这是由访问类引起的。

于 2013-09-28T22:17:55.497 回答