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">&nbsp</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

Sancho Panza’s picture

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.

jludwig’s picture

I added the ?> at the end to close off the php coloring. The actual module leaves them out.

Thanks, though.

Sancho Panza’s picture

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.

jludwig’s picture

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

jludwig’s picture

Update:

I fixed some of the messups (i.e. where it says 'module_test' instead of 'modal_test') and the error still occurs.

Sancho Panza’s picture

I downloaded your files. When I opened the file it looked like this on my editor.

<?php
/**
* 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,
  );

When looked for the hex codes, I found the characters C2 A0 instead of a space or a tab.

C:\wamp\www\COSASV~1\sites\all\modules\MODAL_~1>debug modal_~2.mod
-d
14F9:0100  3C 3F 70 68 70 0A 2F 2A-2A 0A 2A 20 49 6D 70 6C   <?php./**.* Impl
14F9:0110  65 6D 65 6E 74 61 74 69-6F 6E 20 6F 66 20 68 6F   ementation of ho
14F9:0120  6F 6B 5F 6D 65 6E 75 28-29 2E 0A 2A 2F 0A 66 75   ok_menu()..*/.fu
14F9:0130  6E 63 74 69 6F 6E 20 6D-6F 64 61 6C 5F 74 65 73   nction modal_tes
14F9:0140  74 5F 6D 65 6E 75 28 29-20 7B 0A C2 A0 20 24 69   t_menu() {... $i
14F9:0150  74 65 6D 73 20 3D 20 61-72 72 61 79 28 29 3B 0A   tems = array();.
14F9:0160  0A C2 A0 20 24 69 74 65-6D 73 5B 27 6D 6F 64 61   ... $items['moda
14F9:0170  6C 5F 74 65 73 74 27 5D-20 3D 20 61 72 72 61 79   l_test'] = array
-d
14F9:0180  28 0A C2 A0 C2 A0 C2 A0-20 27 74 69 74 6C 65 27   (....... 'title'
14F9:0190  20 3D 3E 20 27 4D 6F 64-61 6C 20 74 65 73 74 27    => 'Modal test'
14F9:01A0  2C 0A C2 A0 C2 A0 C2 A0-20 27 61 63 63 65 73 73   ,....... 'access
14F9:01B0  20 63 61 6C 6C 62 61 63-6B 27 20 3D 3E 20 54 52    callback' => TR
14F9:01C0  55 45 2C 0A C2 A0 C2 A0-C2 A0 20 27 70 61 67 65   UE,....... 'page
14F9:01D0  20 63 61 6C 6C 62 61 63-6B 27 20 3D 3E 20 27 6D    callback' => 'm
14F9:01E0  6F 64 61 6C 5F 74 65 73-74 5F 70 61 67 65 27 2C   odal_test_page',
14F9:01F0  0A C2 A0 20 29 3B 0A 0A-C2 A0 20 24 69 74 65 6D   ... );.... $item

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.

jludwig’s picture

Wow! Thank you, thank you, thank you! It worked. I'll have to pay attention to that from now on.