1

I am having issues with a template - in the template.php there is code causing a warning:

Warning: Creating default object from empty value in theme545_preprocess_html() (line 31 of /home/noramtow/public_html/sites/all/themes/theme545/template.php).

The line in questions is this:

$vars['rdf']->version = 'version="HTML+RDFa 1.1"';

The whole section of code looks like this:

function theme545_preprocess_html(&$vars) {
if (module_exists('rdf')) {
$vars['doctype'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML+RDFa 1.1//EN">' . "\n";
$vars['rdf']->version = 'version="HTML+RDFa 1.1"';
$vars['rdf']->namespaces = $vars['rdf_namespaces'];
$vars['rdf']->profile = ' profile="' . $vars['grddl_profile'] . '"';
} else {
$vars['doctype'] = '<!DOCTYPE html>' . "\n";
$vars['rdf']->version = '';
$vars['rdf']->namespaces = '';
$vars['rdf']->profile = '';
}
$vars['classes_array'][] = 'body';

I'm not great with PHP - anyone have any idea how to fix this or what's causing it?? Thanks for any help you can give!! Candace

0

It sounds like your system wants to make sure $vars['rdf'] is a valid object before assigning properties to it.

Try adding:

if (empty($variables['rdf']) || !is_object($variables['rdf'])) {
  $vars['rdf'] = new stdClass();
}

Just above your line 31.

For safety's sake, add it above

if (module_exists('rdf')) {

That way the object will get initialized regardless of whether the RDF module is enabled or not.

  • I added it an uploaded, but it's still showing the same warning. :-( – everaftergraphics Jun 18 '14 at 2:21
  • Rats. Do you know what version of PHP you have? – calebtr Jun 18 '14 at 20:20
  • No, but they're a really good hosting company, and they're usually really updated. – everaftergraphics Jun 18 '14 at 23:11
  • Keeping PHP at the latest version would be risky for a host - they might break Drupal and Wordpress. So you are on Drupal 7 you are using PHP 5.2 or 5.3 - I was able to replicate this error on 5.3 but not 5.2. I updated my code with the solution that works for me. – calebtr Jun 19 '14 at 8:38
  • Has anyone told you that you are BRILLIANT??!! THANK YOU!!!! – everaftergraphics Jun 19 '14 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.