Re: POST variable and PHP 7

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx>
> 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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux