RE: POST variable and PHP 7

From: Date: Wed, 29 Apr 2020 20:37:26 +0000
Subject: RE: POST variable and PHP 7
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-327119@lists.php.net to get a copy of this message
You are correct that under PHP5 no Notice was issued. While these messages will fill-up your apache error log, they are not an error per se. You need to check to see if the variable is set first: if (isset($_POST["pizza"])) { $glbPizza = $_POST["pizza"]; } -----Original Message----- From: Nick Kelley <nick@nickkelleystuff.com> Sent: Wednesday, April 29, 2020 3:26 PM To: php-general@lists.php.net Subject: Re: POST variable and PHP 7 CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you validate the sender and know the content is safe. 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'] ?? ''; ?> See: https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

« previous php.general (#327119) next »