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 trialHenrik Hansen
23,176 PointsA comment on testing for empty strings...
Instead of testing the value of your variable, object, array or others for the empty string value, you should use the php function empty($var), witch does not throw a notice or warning if the variable does not exist. The php function isset($var) can also be used, but it does not test the value at all, thus isset($var) will return true.
<?php
// This will throw a Notice if the title property does not exist:
if ( $wptreehouse_profile->badges[$i]->courses[1]->title != '' ) {
// do stuff if title is not empty
}
//This will check if the property exists and if the value is empty or false:
if ( !empty( $wptreehouse_profile->badges[$i]->courses[1]->title ) {
//do stuff if title exists and is not empty
}
//This is a longer way to do it:
if ( isset( $wptreehouse_profile->badges[$i]->courses[1]->title ) &&
$wptreehouse_profile->badges[$i]->courses[1]->title != '' ) {
//do stuff if title exists and is not empty
}
?>
Even though all of these will give the same result, all types of notices and warnings should be avoided.
Henrik Hansen
23,176 PointsHenrik Hansen
23,176 PointsAlso, I think there should be a way to discuss courses/videos/parts of it without posting it as a question. Or did I just miss that function?