Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Working with $_GET and $_POST in PHP $_GET and $_POST Using $_GET variables in a Function

Dublicate code

<?php
if (isset ($_GET['name'])) {
    $name = $_GET['name'];
}  
/* as the same if statement is within the function itself now
    the code snippet above is obsolete, isn' t it?
    If it is redundant, please update the code example so that others don' t get confused.
    Otherwise I appreciate any hint why the dublicate code is needed here.
   Thank you.
*/

function greeting() {
        if (isset ($_GET['name'])) {
            $name = $_GET['name'];
            echo "Hello, " . $name;
        }
}
greeting();
?>

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, devis ! I agree with you about the duplicate code. I'm not sure if it was included for emphasis, but I will bring it up with the education team. Thank you for bringing this to my attention! :smiley:

Hello Jennifer, thank you for the feedback :smiley:

Hi Jennifer, it's still here! And in the quiz as well. Also confused me. Did you get an answer as to why it's added twice?

Jaroslav BΓ­lek
Jaroslav BΓ­lek
9,415 Points

Why is isset doubled? To make it double safe?