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 PHP Basics Daily Exercise Program String Manipulation

Andrew G
Andrew G
7,541 Points

Hi there, I think there may be a bug in the PHP basics challenge. I get an error when adding $firstName = 'Rasmus ';

Hi there, I think there may be a bug in this PHP basics challenge. I get an error when adding $firstName = 'Rasmus ', with the space in order to ensure that $fullName is correct. My code:

<?php
$firstName = 'Rasmus ';
$lastName = 'Lerdorf';

$fullName = $firstName . $lastName;

echo $fullName;
?>
index.php
<?php

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


?>

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

This is not a bug. The challenge specifies that $firstName should be set to the string "Rasmus", not "Rasmus ". The space at the end of the way you have it now shouldn't be there

Andrew G
Andrew G
7,541 Points

Thanks Mod, but it is confusing, as Alina uses that strategy for adding a space in between names in the lesson, so it's the first thing that comes to mind, and from memory she doesn't use the concatenation technique required to solve it at all in that context: .' '.

Also, I'm only a beginner at PHP, but isn't the value still Rasmus, even if the string is 'Rasmus '? The question requests that the value be set to Rasmus.

Michael Hulet
Michael Hulet
47,912 Points

No, the value is different if there's a space at the end of the string. A space is an extra character, and a string with more characters is intrinsically different from another string with fewer. The challenge doesn't ask you to worry about combining names until the 2nd step. In the first step, it just asks you to make $firstName be "Rasmus" (not "Rasmus "), and remember that each step of a challenge must pass all the tests of the previous step, so modifying variables from the previous step is not an option here

Andrew G
Andrew G
7,541 Points

Awesome, thanks for clarifying. I'm really enjoying the beginner php track, and Alina's clear and precise teaching style.:)