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 Unit Converter Integers

Ryan Sprouse
Ryan Sprouse
3,291 Points

I have been following along with the php basics videos and when I run the php in workspace it doesn't run.

I am following the videos step by step and have the same code written as the instructor.

this is the code:

<?php $num_one = 1; $num_two = 2; $num_three = 3;

echo $num_one; ?>

When I run it in the console it fails to run. Like this:

treehouse:~/workspace$ php numbers.php treehouse:~/workspace$

There is no "1" that should show up. What am I doing wrong?

2 Answers

Jason Cook
Jason Cook
11,403 Points

Your code runs correctly with no errors. The "1" might perhaps be hiding right in front of the shell prompt, following your command call, which is what happened to me also. You can try the following code, which will concatenate a line break, before displaying the shell prompt again, making it easier to see the output.

<?php 
$num_one = 1; 
$num_two = 2; 
$num_three = 3;
echo $num_one . PHP_EOL;

I know this response is a couple hours late, but hope it helps all the same :)

Jason Cook
Jason Cook
11,403 Points

No problem, Ryan! Glad I could help :)

Jeffrey Libatique
Jeffrey Libatique
6,701 Points

I encountered the same problem. I'm glad that there's a question about this error with an answer and followed it but again encountered another problem.

Below is the response that I got on the console when following Jason's advice.

Parse error: syntax error, unexpected '.', expecting end of file in /home/treehouse/workspace/numbers.php on line 6

Jason Cook
Jason Cook
11,403 Points

Jeffrey, the only way I've been able to duplicate the error message you received, is by adding a period on line 6. Make sure you don't have an extraneous '.' after terminating the last line of code. I know this response is slow, so you probably already solved it, but just in case.