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 trialJennifer Nordell
Treehouse TeacherI 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
Jennifer Nordell
Treehouse TeacherSorry about that, Michael Hulet. I've updated my question to include a link to the relevant video
3 Answers
Rich Donnellan
Treehouse Moderator 27,696 PointsGlad to help out, Jennifer Nordell!
For anyone curious of my debugging process:
- Referenced error message and line number from OP
- Referenced the json_decode() documentation; specifically "Example #3 common mistakes"
- Copy JSON data from the
database.json
file - Paste data into an online JSON validator (any will do)
- Results returned a parse error on line 103
Sometimes all you need is a second set of eyes and some luck. :)
Jennifer Nordell
Treehouse TeacherActually, 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
Alena Holligan
Treehouse Teacherwonder how it got there... this was the file I had been using. But I'll update the template
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsThis 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
Treehouse TeacherOut 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.
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsMy bad, I didn't watch the entire video and must have missed that part, but I was looking at 7:38 :-P
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsWhich video are you currently on?