Hello everyone,
I'm getting PHP syntax errors on two different servers with two different installs with the same correct (as far as I can tell) code:
For example, this:
/**
* Implementation of hook_menu().
*/
function modal_test_menu() {
$items = array();
$items['modal_test'] = array(
'title' => 'Modal test',
'access callback' => TRUE,
'page callback' => 'modal_test_page',
);
$items['modal_test/form'] = array(
'title' => 'AJAX modal dialog',
'access callback' => TRUE,
'page callback' => 'modal_test_popup',
'type' => MENU_CALLBACK,
);
return $items;
}
function modal_test_page() {
ctools_include('ajax'); // Module include the dependence it needs for ajax.
ctools_include('modal');
ctools_modal_add_js();
$output = ctools_modal_text_button(t('Click Here'), 'modal_test/form', t('Pop me up'));
$output .= '<div id="modal-message"> </div>';
ctools_include('plugins');
return $output;
}
function modal_test_popup() {
ctools_include('ajax');
ctools_include('modal');
$form_state = array('ajax' => TRUE);
$output = ctools_modal_form_wrapper('module_test_form', $form_state);
if (!$output) {
$output = array();
$output[] = ctools_ajax_command_replace('#modal-message', '<div id="modal-message">' . $form_state['message'] . '</div>');
$output[] = ctools_modal_command_dismiss();
}
ctools_ajax_render($output);
}
function module_test_form(&$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function module_test_form_submit(&$form, &$form_state) {
$form_state['message'] = t('Message: %message', array('%message' => $form_state['values']['text']));
}
returns the following error:
Parse error: syntax error, unexpected T_VARIABLE in /home/justin/modules/modal_test/modal_test.module on line 6 Call Stack: 0.0002 649080 1. {main}() /srv/http/drupal6/index.php:0 0.0021 1008616 2. drupal_bootstrap() /srv/http/drupal6/index.php:21 0.0238 4145280 3. _drupal_bootstrap() /srv/http/drupal6/includes/bootstrap.inc:989 0.0294 5253512 4. _drupal_bootstrap_full() /srv/http/drupal6/includes/bootstrap.inc:1080 0.0478 8774016 5. module_load_all() /srv/http/drupal6/includes/common.inc:2618 0.1116 19455328 6. drupal_load() /srv/http/drupal6/includes/module.inc:14
Both sites work fine without the module and once I enable it, this error occurs. I wrote another module and again, it's bringing errors the first time I use a variable.
This is really frustrating. ._.
Perhaps I should post this on a PHP board?
Thanks,
Justin
Comments
Not an expert, but may be this one?
Check at:
http://drupal.org/node/206754
Where it reads
Coding Standards
As per the Coding standards, omit the closing ?> tag. Including the closing tag may cause strange runtime issues on certain server setups. (Note that the examples in the handbook will show the closing tag for formatting reasons only and you should not include it in your real code.)
All functions in your module that will be used by Drupal are named {modulename}_{hook}, where "hook" is a pre-defined function name suffix. Drupal will call these functions to get specific data, so having these well-defined names means Drupal knows where to look. We will come to hooks in a while.
I added the ?> at the end to
I added the ?> at the end to close off the php coloring. The actual module leaves them out.
Thanks, though.
If I can be of any further help...
Sorry for the very basic answer. I did not check your background.
I have copied the code and pasted on a local WAMP installation and the code worked without any problem. Tried to include strange character, erase semicolons, brackets, etc, but could not get that specific error.
I also copied to a small personal site on Hostmonster and could not reproduce the error. It worked without problems.
Using Drupal 6.15 on both
PHP 5.2.9 in local WAMP
PHP 5.2.11 on Hostmonster
If you copy the original .module and .info files where I can download them I can dedicate a few minutes to try them and see.
Thanks you! This is strange,
Thanks you! This is strange, isn't it? Here's a tarball.
http://www.mediafire.com/?mnnj5di4drn
Edit: Here's the exact error:
Parse error: syntax error, unexpected T_VARIABLE in /home/justin/modules/modal_test/modal_test.module on line 6 Call Stack: 0.0096 646896 1. {main}() /srv/http/drupal6/index.php:0 0.0624 1006480 2. drupal_bootstrap() /srv/http/drupal6/index.php:21 0.5118 4143016 3. _drupal_bootstrap() /srv/http/drupal6/includes/bootstrap.inc:989 0.5429 5251192 4. _drupal_bootstrap_full() /srv/http/drupal6/includes/bootstrap.inc:1080 0.5995 8771424 5. module_load_all() /srv/http/drupal6/includes/common.inc:2618 1.2291 19452160 6. drupal_load() /srv/http/drupal6/includes/module.inc:14
Update: I fixed some of the
Update:
I fixed some of the messups (i.e. where it says 'module_test' instead of 'modal_test') and the error still occurs.
Non ASCII Character
I downloaded your files. When I opened the file it looked like this on my editor.
When looked for the hex codes, I found the characters C2 A0 instead of a space or a tab.
And, as expected, it produced an error in line 6 when running. C2 A0 is UTF-8 symbol for non break space. May it be that you are using your editor with unicode enconding?
I replaced those symbols with normal spaces and it runs OK again.
Wow! Thank you, thank you,
Wow! Thank you, thank you, thank you! It worked. I'll have to pay attention to that from now on.