Drupal 7自定义模块Strict Standards报错求助:仅变量应按引用传递
This isn't a severe problem—it's just a PHP strict standards warning, not a fatal error that would break your site. It's more of a code compliance issue than a critical bug, but fixing it is straightforward and keeps your code clean.
The Root Cause
The error occurs because drupal_render() expects a variable passed by reference, but you’re directly passing the return value of drupal_get_form('vb_ymlp_form')—a temporary value, not a named variable. PHP’s strict standards flag this as a violation.
Simple Fix
Just store the form in a variable first before passing it to drupal_render():
function vb_ymlp_block_view($delta = ""){ module_load_include('inc', 'vb_ymlp', 'vb_ymlp.form'); $block = array(); if($delta == 'vb_ymlp_block'){ // Assign form to a variable first to comply with strict standards $form = drupal_get_form('vb_ymlp_form'); $block['content'] = drupal_render($form); } return $block; }
Why This Works
By assigning drupal_get_form()'s result to a variable ($form), you create a referenceable value that meets PHP’s strict standards requirements. This eliminates the warning without changing the functionality of your block.
内容的提问来源于stack exchange,提问作者user1532669

