Re: POST variable and PHP 7

From: Date: Wed, 29 Apr 2020 20:25:42 +0000
Subject: Re: POST variable and PHP 7
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-327117@lists.php.net to get a copy of this message
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 (#327117) next »