Re: POST variable and PHP 7
| From: | Paul M Foster | Date: | Wed, 29 Apr 2020 21:42:36 +0000 |
| Subject: | Re: POST variable and PHP 7 | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327121@lists.php.net to get a copy of this message | ||
On Wed, Apr 29, 2020 at 01:25:42PM -0700, Nick Kelley wrote:
>
>
> On Wed, Apr 29, 2020 at 4:13 pm, Paul M Foster <paulf@quillandmouse.com>
> wrote:
> > The first time through, under PHP 7, this will error out, because there
> > is no 'pizza' index for the $_POST array. The $_POST array is empty.
> >
> > Seems like I used to use this exact idiom under PHP 5, and it worked,
> > but under PHP 7 it doesn't.
> >
> > Am I mis-remembering? If not, is there some common way around this under
> > PHP 7?
> >
>
> I can't speak to whether this would have worked in PHP 5 (I'm new enough to
> PHP that I started out on 7), but I think the fix you want is the new null
> coalescing operator ("??"), like this:
>
> <?php echo $_POST['pizza'] ?? ''; ?>
>
Excellent suggestion. I wasn't aware of this change. Thanks.
Paul
--
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com