Re: Destroy a session var passed as an argument

From: Date: Wed, 24 Apr 2002 19:03:10 +0000
Subject: Re: Destroy a session var passed as an argument
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-94433@lists.php.net to get a copy of this message
On Wednesday, April 24, 2002, at 02:59 PM, Julio Nobrega Trabalhando wrote:
I have a simple function that returns a message: function showError ($mensagem) {
    return '<div class="erro">' . $mensagem . '</div>';
} And this is how I use it: if (isset($_SESSION['forum']['error']['insert'])) {
    echo showError($_SESSION['forum']['error']['insert']));
} But I want that when the function is used the session variable is destroyed. A simple unset($mensagem) inside showError() gives me back this: Warning: Undefined variable: mensagem in c:\www\lib\sistema\formularios\formularios.inc.php on line 92
The problem is that there is no variable called $mensagem in your function. You are using a reference to something else with the name $mensagem, but you are not passing the value by reference -- try this: function showError(&$mensagem) // note the '&' before $mensagem { return '<div class="erro">' . $mensagem . '</div>'; } And let me know if that works or doesn't work. (It's kind of a hunch, hard to tell from your code if it will work.) Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#94433) next »