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

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

I know I'm missing something small...

Hi everyone! I'm currently working my way through the brand new Designing Interfaces in PHP course, but I've hit a stumbling block. I'm sure it's something small I'm missing.

I'm receiving this error:

Notice: Trying to get property of non-object in /home/treehouse/workspace/src/classes/jsonRepository.php on line 12
NULL

I have yet to see how my code differs from the instructors and am hoping some of you "eagle-eyed" people can help me spot my mistake. I've been over this video in excess of a dozen times now. I've even been on stack overflow which suggests I add a flag of TRUE as a parameter to the offending line. I have, however, not seen any changes.

My workspace is available here.

I look forward to receiving any help with this! Thank you in advance :sparkles:

Michael Hulet
Michael Hulet
47,913 Points

Which video are you currently on?

3 Answers

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,696 Points

Glad to help out, Jennifer Nordell!

For anyone curious of my debugging process:

  1. Referenced error message and line number from OP
  2. Referenced the json_decode() documentation; specifically "Example #3 common mistakes"
  3. Copy JSON data from the database.json file
  4. Paste data into an online JSON validator (any will do)
  5. Results returned a parse error on line 103

Sometimes all you need is a second set of eyes and some luck. :)

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

Actually, it turns out it was very small. In the database.json file there is a trailing comma on line 103. Removing this repairs the JSON and makes it return the object that was intended. Thanks heaps to Rich Donnellan for helping locate it! Tagging Alena Holligan for notification of this small error in the JSON file :sparkles:

Alena Holligan
Alena Holligan
Treehouse Teacher

wonder how it got there... this was the file I had been using. But I'll update the template

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

This line looks different from the video, but not sure if that's it? :-)

index.php

var_dump($repo->all('posts'));
var_dump($repo->find('posts')); // Alena uses ->find instead of ->all
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Out of curiosity, which video are you looking at? At 7:19 of this video, it says

var_dump($repo->all('posts'));

At which point, the video moves to the next frame and her website shows a var_dump of at least something, where mine simply shows an error.