Re: $POST and $_SESSION
| From: | Daniel Brown | Date: | Thu, 15 Mar 2012 18:35:49 +0000 |
| Subject: | Re: $POST and $_SESSION | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317036@lists.php.net to get a copy of this message | ||
On Thu, Mar 15, 2012 at 14:31, Stuart Dallas <stuart@3ft9.com> wrote:
>
> The @ prefix is banned from all code I go anywhere near - it's evil! I've used the
> following 'V' function for a long time, primarily for accessing the superglobals but it
> works for any array.
>
> <?php
> session_start();
> $_SESSION['first_name'] = $first_name = V($_SESSION, 'first_name');
>
> function V($arr, $key, $def = null) {
> return isset($arr[$key]) ? $arr[$key] : $def;
> }
> ?>
For the most part, I agree with you, but for this particular
example, it simply silences the notice for an undefined variable,
should it not be set, at the time of the function call. In nearly any
other case, though, I'm totally with you.
--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/