We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39073
    • 15 Posts
    Hi everyone,

    I updated a site this morning from 1.0.4 to 1.0.6 and now I'm getting an error when trying to access the site.

    Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /home/bpa/public_html/manager/includes/protect.inc.php on line 36

    Is this something I can easily fix?
      • 39073
      • 15 Posts
      I compared the protect.inc.php files from 1.0.5 and 1.0.6 and noticed that line 36 in the file from 1.0.6 reads
      foreach ($target as $key => &$value) {
      where line 36 from the 1.0.5 file reads
      foreach ($target as $key => $value) {
      I edited out the ampersand in the 1.0.6 file and it now appears to be working. I don't know much about PHP however, so I would really appreciate if someone could reassure me that I have done the right thing, or tell me if it's going to effect the security of my site?

      Thanks!
        • 16278
        • 928 Posts
        I think the update to protect.inc.php is the raison d'être of MODX 1.0.6, so it would be better to investigate the reason for the error rather than work around it. Deleting the ampersand will change the way the code is working. First thing to check is what version of PHP you are using - possibly you are seeing behaviour from an older version?

        I'm not super expert with PHP either, I just use it a lot, so a real expert may correct me here: Most often, an ampersand before a variable name is used to pass an argument (e.g. a function parameter) "by reference", rather than "by value". Without the ampersand, a function uses its own copy of the parameter. With it, the function updates the original variable, similar to using a global variable.
        (Lots on this in the PHP manual)

        Things are already getting more complicated when you consider ampersands within foreach loops, but I think the main point of this one is to update the actual elements of the array, not just use values from it. See http://php.net/manual/en/control-structures.foreach.php.

        ;) KP
          • 27704
          • 21 Posts
          Last week I tried to install a 1.0.6 Version. The download was brand-new. But after the install routine, when I should have been led to the manager-login, I faced the same error.
          Tried to find out what's going wrong in the german forum. But until now, no success.
          The PHP-version on the server is 4.4.9-0.dotdeb.1.
          If you find something new solving the problem, I would be glad, too.

          Thx

          Smartsoul
            • 39073
            • 15 Posts
            Hi kp52,

            I have just inquired with the host as to what version of PHP is on the sever. Hopefully if it's an old version, upgrading will be an option (not sure what I'm going to do if it isn't)

            Smartsoul, good luck. Please let me know if you find out anything new.
            • You can find out what version with a simple info.php file containing a phpinfo() function call
              <?php
              phpinfo();
              
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 27704
                • 21 Posts
                I think, this error will occur in case of a php-version that is too old for 1.0.6.

                Yesterday I installed the exactly same MODx-pack (same download) on a server with PHP5 running and there I had no error anymore.

                For the moment this is a solution for me, but if someone has no possibility to move to another webspace the problem will exist on.
                Maybe the hoster is able to upgrade the PHP running on the server.
                • The issue is about how the version of PHP deals with pass-by-reference syntax. Newer versions of PHP will throw a warning if the old method of pass-by-reference is used.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 16278
                    • 928 Posts
                    An even easier way to check your PHP version: go to Evo manager's Tools > Reports > System Info page, where there's a link to phpinfo()

                    ;) KP
                    • Well, that's very true if you can get the Manager open wink
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org