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 Building Websites with PHP Dependency Management Autoloading

Barry Meindl
Barry Meindl
6,192 Points

I'm not seeing 'Hello World!' or getting 'app.txt' file after '$log->addWarning' runs

Everything has been going smoothly for me until now. However, it's the one line ($log->addWarning('Foo');) that's giving me problems. When I preview/refresh the browser, Hello World! no longer echoes and it doesn't create the app.txt file.

I've tried refreshing the file tree as well as commenting out everything up until that line and it just won't work. However, if I keep everything else and only comment out $log->addWarning('Foo'); it at least echoes Hello World.

Here is my entire index.php file:

<?php

require 'vendor/autoload.php'; date_default_timezone('America/New_York');

$log = new Monolog\Logger('name'); $log->pushHandler(new Monolog\Handler\StreamHandler('app.txt', Monolog\Logger::WARNING));

$log->addWarning('Foo');

echo 'Hello World!';

I'm really stuck on this one. Any help or advice would be really appreciated. Thank you.

I'm having the same problem. It's the line:

$log->addWarning('Foo');

I think Workspaces is having a problem writing to the file and it crashes.

2 Answers

From what I understand it is a problem with workspaces I kept getting a 500 error. I could not get it to work at all. Your best bet rather than being endlessly frustrated, is to install Composer globally on you system and follow along using your own text editor. Here is a link to a video that clearly explains how to install on windows https://www.youtube.com/watch?v=ZocYVPP3nQY For Mac and Linux/Unix, you install from the terminal.

Just make sure you run composer on the project root folder in your www or htdocs folder. Then you can install monolog by typing composer require monolog/monolog in the command line. Hope this helps :)

Barry Meindl
Barry Meindl
6,192 Points

Alright, at least it's not just me. Thank you both for responding. Also, thank you for the tutorial Edward, I'll definitely have to take a look at it. It looks like that's the best option right now.

Thanks for the suggestion, Edward. I went through the videos again with Compser installed in my own Linux dev environment, and it works great. A bit more work, but definitely better for learning.

Glad I could be of help :)

I don't use Workspaces, instead I use Koding which is another cloud-based IDE that feels similar to Workspaces. I am having the same exact issue when accessing the index.php file from the browser, however I noticed that I don't have issue when executing the index.php file from the command line.