0
  <?php
define('PW_AUTH', '3x1x7MEguZSVIaUVHdBG4XXXXXXXXXXXXXXXXXXXXXXXXXXXxgfHPPAMqmX1VmYH5k6GFYo8n0QdmexUSQRWpvoFYwVACAnG');
define('PW_APPLICATION', '2XXFX-XXx7C');
define('PW_DEBUG', true);

function pwCall($method, $data = array()) {
    $url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
    $request = json_encode(['request' => $data]);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    if (defined('PW_DEBUG') && PW_DEBUG) {
        print "[PW] request: $request\n";
        print "[PW] response: $response\n";
        print "[PW] info: " . print_r($info, true);
    }
}
pwCall('createMessage', array(
                  'application' => PW_APPLICATION,
                  'auth' => PW_AUTH,
                  'notifications' => array(
                          array(
                              'send_date' => 'now',
                              'content' => 'Send this content to user',


 )
                      ),
              )
            );
    ?>

PHP is telling me that there is an error

Parse error: syntax error, unexpected '[', expecting ')' in /home/a5047433/public_html/pushtest.php on line 8

how ever when i run it on a php tester it says its ok and worrks as expected any body know what the issue is

I tested this code at http://phpfiddle.org/ and it works as expected

ERROR i am gettting: Parse error: syntax error, unexpected '[', expecting ')' this is on a 000 web host accoount Any help is greatly appreciated thanks

A Kel
  • 75
  • 9

2 Answers2

3

Yes, short array syntax is only since PHP 5.4. So double-check which php is used by this VHost (just put a phpinfo into it).

BTW, it's a very old version; you should update as soon as possible.

capqch
  • 46
  • 2
  • Big +1 for the last bit. The versions of PHP that don't understand the new array syntax are all end-of-lifed and thus **dangerously** insecure to run in production. If your webhost is still stuck on PHP 5.3 they're not a good host. – ceejayoz Mar 10 '16 at 16:13
  • thanks for your answear is it possible to writ the same thing as not a short array – A Kel Mar 10 '16 at 16:15
  • Of course: `['a' => 3]` as `array('a' => 3)` – capqch Mar 10 '16 at 16:20
  • i dont have much experience with php any tips or tutorials on hoe i would to it thanks – A Kel Mar 10 '16 at 16:22
  • $request = json_encode(array('request' => $data)); as opposed to $request = json_encode(['request' => $data]); is that what you mean @capqch – A Kel Mar 10 '16 at 16:26
  • Thanks very much capqch fixed my problem your help is appreciated thanks – A Kel Mar 10 '16 at 16:27
-1

For escaped this error you need write source code, by coding style not short if array and over construction

array(
   'key' => 'value'
)
// don't use ['key' => 'value'] is not correct
if(expression) {
   // blablabla
} else {
  //blablabla
}
// don't use expression?'':''

if you use full construction you see each {} and each [] and over symbols, and this easy understand. And if you to be work in team you collegies no understanding your code.

Naumov
  • 1,167
  • 9
  • 22
  • 1
    `['key' => 'value']` is entirely correct in any currently supported version of PHP. OP's webhost is running a dangerous and unsupported version of PHP. – ceejayoz Mar 10 '16 at 16:14
  • @ceejayoz currently but if you wont use `[ ]` and don't use array() you can getting this code `$conf=[[['testing'=>[['test'=>'blabla']]]]]; isset($conf[0][0]['testing'])? 'test' : 'test2'` is don't readable, don't support... – Naumov Mar 10 '16 at 16:19
  • who downvote please write comment – Naumov Mar 10 '16 at 16:22
  • I downvoted, and it's possible to make that (very contrived) code perfectly readable. https://gist.github.com/ceejayoz/0165d447ba9d6732c16e – ceejayoz Mar 10 '16 at 16:58
  • @ceejayoz try jast hardly your algorithm. for example https://github.com/lnroma/testtask/blob/master/fortest.php this don't readable. when you have 10-15 string code you can read, but if you have 300-500 string code in file this don't readable – Naumov Mar 10 '16 at 18:47
  • That's perfectly readable, and if you've got a 300-500 item array in your source you've likely done something fundamentally bizarre that could be coded better. Your examples don't make any sense, either - why would you need three levels of empty array nesting like that? Fundamentally, the `[]` shorthand just replaces `array()` - code isn't going to be less readable by using it. – ceejayoz Mar 10 '16 at 18:51
  • I just try say, better way use coding style ( I'm use zend coding style) and you application will be currect work on php 5.3 and 5.6. You can use shotr tags, array, over construction. But you got code worked only you computer. I'm php backend developer and know this in practice. Difficalty work on not documentation code, writing be monkeys ))). Ok sorry for my English – Naumov Mar 10 '16 at 22:40
  • And this imortant for begining developers. – Naumov Mar 10 '16 at 22:41