Project:dependantDropdown
Version:5.x-1.0-beta
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /usr/local/apache/htdocs/sitename.com/drupal474/modules/dependantDropdown/dependantDropdown.module on line 79

Note: drupal 4.7.4

Comments

#1

The error comes in this line:
foreach ($form as $fieldname => &$field)

It seems that this syntax is not accepted: "=> &$"

As of PHP 5, you can easily modify array's elements by preceding $value with &.
This will assign reference instead of copying the value.

$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)

What is your PHP version?
Do you know what is drupal policy towards php versions?
I'll take a look how to refactor the code so it'll work on previous versions.

hed

#2

Quoted from here:

As of Drupal 4.6, the CMS requires PHP version 4.3.3+ (PHP 5 is supported for the 4.6 release). Drupal 4.2 to 4.5.2 inclusive require PHP version 4.1+. Older versions of Drupal will run on PHP 4.0.6+. We recommend using the latest version of PHP 4.x.

In this case i think you could just do

<?php
$selectField
= &$form[$fieldname][$filter]
?>

instead of

<?php
$selectField
= &$field[$filter];
?>

and drop the reference in the foreach.

#3

Server is setup as follows:

PHP Version 4.4.0
Apache/1.3.33 (Unix) PHP/4.4.0 FrontPage/5.0.2.2635 mod_throttle/3.1.2 mod_ssl/2.8.22 OpenSSL/0.9.7a

#4

scroogie answer is right i guess,
now does any of you guys know how do i maintain two branches in CVS to post this fix?
because my CVS version is already forwarded to 5

tnx,
hed

#5

#6

Looking forward for a patch

#7

A patch?
I'm missing something
i opened another branch for 4.7 and fixed it there
My main branch is 5.0 compatible
I must admit that i don't understand those releases.

#8

I downloaded and installed both 4.7 releases on 1/05/2006 and getting same parse error.

#9

Ive changed this function and it works for me on php 4.4.4:

<?php
function dependantDropdown_connect_filtering_field(&$form){
    foreach (
$form['#filteringMatch'] as $filter => $filtered) {
       
$selectField = NULL;
        if (isset(
$form[$filter])) {
           
$form[$filter]['key']['#attributes']['title'] = $filtered;
           
$form[$filter]['key']['#attributes']['class'] = "filteringField";
        } else {
         
$newform=array();
            foreach (
$form as $fieldname => $field){
             
$newform[$fieldname]=$field;
                if (
$field['#type'] == 'fieldset' && isset($field[$filter])){
                       
$newform[$fieldname][$filter]['key']['#attributes']['title'] = $filtered;
                       
$newform[$fieldname][$filter]['key']['#attributes']['class'] = "filteringField";
                }
            }
     
$form=$newform;           
        }
    }
}
?>

#10

Title:Parse error message» same error in version for drupal 5.0
Version:» 5.x-1.0-beta

The latest 5.x version download has the same problem:

Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /srv/www/vhosts/swlspaces.com/subdomains/d5/httpdocs/sites/all/modules/dependantDropdown/dependantDropdown.module on line 69

replacing the line
foreach ($form as $fieldname => &$field) {
with

foreach (array_keys($form) as $fieldname) {
    $field =& $form[$fieldname];

makes the error go away ... will test now if it works as expected.
nobody click here