global $var does not work in PHP

Asked

Viewed 79 times

0

I have the following code:

<?php
$_this =& get_instance();

function ConfiguracoesSistema($coluna){

    global $_this;

    $configuracoes = $_this->db->get('configuracao');

    if($configuracoes->num_rows() > 0){

        return $configuracoes->row()->$coluna;
    }

    return false;
}
?>

I need to get the variable that’s out of function $_this and use it within the function Configurationsystem(). The problem is that she is not accessing, even using the word global. In case I put $_this =& get_instance(); within the function, it works. My PHP is version 5.6.

1 answer

0

Try calling it inside the function without the "global":

<?php
$_this =& get_instance();

function ConfiguracoesSistema($coluna){

    $configuracoes = $_this->db->get('configuracao');

    if($configuracoes->num_rows() > 0){

        return $configuracoes->row()->$coluna;
    }

    return false;
}
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.