Why it gets null after include?

Hello all, please, PLEASE :injured:

Note: this is all on separate files, but I’ve put them together so that I can debug easier.

ISSUE: I cannot get the success message to display:

Here’s the “thing”:

If the mail is send, put something on this array:

    $resultado['sucesso'] = 'Contacto enviado. Obrigado.';

On the HTML part of this same file:

If the $resultado is set, show the success message, else, display the form:

 <?php if (isset($resultado['sucesso']) || isset($resultado['insucesso'])) { ?>

<?php echo (isset($resultado['sucesso'])) ? '<div>'.$resultado['sucesso'].'</div>':''; ?>


                    <?php } else { ?>

//the form is here

I then start doing var_dumps from top to bottom of this file:


Here (before the first include_once of this excerpt):

<div id="coluna-esquerda">
              <?php var_dump($resultado['sucesso']); ?>
                <?php include_once('Inc/ListaNoticiasInc.php'); ?>
                <?php include_once('Inc/PainelLinkTornarAssociado.php'); ?>


I get the string returned. If I keep on going, one line down with the var_dump, like so:

<div id="coluna-esquerda">
                <?php include_once('Inc/ListaNoticiasInc.php'); ?>
 <?php var_dump($resultado['sucesso']); ?>
                <?php include_once('Inc/PainelLinkTornarAssociado.php'); ?>


I get null.

After the includes, I loose the value of $resultado[‘sucesso’]. Why is this?

Any clue about what’s going on here please?? :injured::injured::injured:

It should be something really stupid because I got this working before. :sick:

Thank you in advance,

Is there a varibale with the same name in Inc/ListaNoticiasInc.php file as well? I suspect that you have the same named variable $resultado[‘sucesso’] so try only var_dumping only $resultado and see if that shows anything for you. Otherwise just share your script in that file Inc/ListaNoticiasInc.php.


I had an include and on that include, I was having: $resultado=array(); hence, emptying what it shouldn’t empty.

THANKS A LOT REALLY!!! I was killing myself on this already.