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??

1
  • 1
    From the array_splice docs: "Note: If replacement is not an array, it will be typecast to one (i.e. (array) $parameter). This may result in unexpected behavior when using an object or NULL replacement.". Maybe there is the problem? Commented Sep 28, 2013 at 22:13

2 Answers 2

17

The "replacement" argument must be an array itself, so you should write

array_splice($this->EventosEntrada, $i, 0, [$EventoLimite]); // note []s
Sign up to request clarification or add additional context in comments.

2 Comments

OH GOD you're a genius. Do the bracket means it's an array slot?
@user1181589: I just go to the docs whenever something unexpected happens :-)
0

maybe its because of that when you introduce a new object, just public variables and functions are available in the specific file you work on. I mean it is cause by access of clsasses.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.