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

rob111
rob111
8,379 Points

Here's my version but it's not letting me pass

Here's my version but it's not letting me pass

<?php

//Place your code below this comment 

$firstName = Rasmus; 
$lastName = Lerdorf;

$fullname = "$firstName $lastName"; 
echo "$fullname was the original creator of PHP \n";

?>

fixed code formatting

Jennifer Nordell Did you delete your answer or did I somehow accidentally delete it? I was fixing the code formatting here and then noticed it was gone.

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

Jason Anello, I did delete it. I found the answer, which in my opinion, is a little odd. I feel like that answer (barring the lack of quotation marks around the strings) should have passed. No, you didn't delete my answer on accident! :smiley:

Tagging Alena Holligan

Task 1 and 2 are allowing the code to pass with notices in the output but task 3 seems to be catching it and not allowing it to pass.

3 Answers

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

Hi there! Ok this is odd I know. And your code does look like it outputs the correct string. However, I found the part that is making it fail. For some reason, it really wants you to use concatenation to put together the fullname.

Take a look:

<?php

//Place your code below this comment
$firstName = "Rasmus";
$lastName = "Lerdorf";

$fullname = $firstName . " " . $lastName;

echo "$fullname was the original creator of PHP\n";
?>

If I do it this way, instead of assigning a string with expanded variable values in it, it suddenly passes! Hope this helps!

On a side note, on step 3 if the names are not included in quotes you will get back a compiler error saying something about usage of an undeclared constant.

Good luck! :sparkles:

Hi Jennifer,

I think there were a few different things going on here that made this more confusing.

One was the unquoted strings and it seems that task 1 and task 2 were letting the notice errors slip by but task 3 is catching it.

The other issue was the space before the line return. That can't be present. The challenge will let you pass with a double quoted string as long as the extra space before the newline isn't there.

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

Jason Anello yes, but that's not quite what I mean. And this is when everything else is otherwise correct with the newline character without the space and the strings in quotation marks.

On step two you can give this code, and it passes step 2.

$fullname = "$firstName $lastName";

But, if you then try to use that variable $fullname in the echo statement in step 3, it fails.

However, if you do this in step 2:

$fullname = $firstName . " " . $lastName;

And without changing anything else about the echo, it passes step 3.

Maybe the challenge is having some kind of problem them.

I just tried again and I'm able to pass without any concatenation.

$firstName = 'Rasmus'; 
$lastName = 'Lerdorf';

$fullname = "$firstName $lastName"; 
echo "$fullname was the original creator of PHP\n";
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

That code does now pass for me also. But it didn't, and I swear it was exactly the same except that I used double quotes on my strings. I wish I had taken a screenshot and sent it to support now.

rob111
rob111
8,379 Points

I don't know what Alena has to do with this but ok.

Rasmus and Lerdorf are not inside quote marks but shouldn't PHP just by default think this is a string? I thought that was the behaviour especially since it's not a number like SIX for example.

I put my code into my editor and run it, my results are:

Rasmus Lerdorf was the original creator of PHP

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

It's not a default behavior that I know of. But again, you are correct in that I can see when I put in my code (and yes, I've passed this challenge before) that it Previews the correct string. To the letter. But, it simply will not pass.

Hi Rob,

Alena is the teacher for this course.

When you don't put quotes around those strings then php thinks it's a constant. In this case, an undefined constant. The way that php handles undefined constants is that it assumes you meant a string of the same name but it also issues a notice error in the output warning you about the use of an undefined constant.

If you check your preview you'll notice that there are some notice errors that are part of the output.

Even though it got you past task 1 and 2 you definitely should not be relying on this behavior. Create a string with quotes if that's what you really intend to do.

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

I added some extra checks and suggestions to help figure things out. You should no longer be able to pass task 1 & 2 without quoting your string. You can use either of the following lines for concatenation.

$fullname = "$firstName $lastName";

OR

$fullname = $firstName . " " . $lastName;

I also included a hint that would let you know that you have extra space in your final string, you have a space between PHP and \n.

Let me know how things work for you now and if there are any improvements I can make :)

Thanks!

I ran through it again and everything seems to test out ok.