-1

I'm using WAMP and tried different browsers. This example is copy paste from w3schools. But I get:

Parse error: syntax error, unexpected ' ' (T_STRING) in C:\wamp64\www\tuto\otro.php on line 10.

Line 10 is: $GLOBALS['y'] = $GLOBALS['x'] + $GLOBAL['y'];

I really can't see why it works on the w3schools editor but not on my browser. Other basic code works fine, WAMP works fine. I have PHP Version 5.6.19 and the tutorial is also PHP5 w3schools code

<!DOCTYPE html>
<html>
    <body>

        <?php
            $x = 5;
            $y = 10;

            function myTest() {
                $GLOBALS['y'] = $GLOBALS['x'] + $GLOBAL['y'];
            } 

            myTest();
            echo $y; // outputs 15
        ?> 

    </body>
</html>
Ivanux
  • 5
  • 3
  • SOLVED My problem is different as I had read before asking... I hope this will help someone in the future: I used copy/paste the code from w3schools and mdn and there was the problem. I had to erase all the spaces, tabs from the code and retype the space myself and it worked. I guess there is something hidden there! If someone knows exactly what please share... Thank you all and I don;t suppose it's possible to restore that -1? xD – Ivanux Feb 27 '17 at 22:02

1 Answers1

3

You are missing 'S' in the syntax $GLOBAL['y'];. So updated script is ,

 $x = 5;
        $y = 10;

        function myTest() {
            $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
        } 

        myTest();
        echo $y; // outputs 15
Naga
  • 2,190
  • 3
  • 16
  • 21