8

I'm trying to initialize a function of CI in my native code.

$cipher->initialize(
        [
         'driver'=>'openssl',
         'key' => $key
        ]
     );

I'm getting an error of Parse error: syntax error, unexpected '['

Can I ask how to fix this?

Using Php 5.3.3

Ligthers
  • 217
  • 1
  • 4
  • 10
  • You're using a version of PHP that does not support new array initialization syntax – Hanky Panky Nov 16 '16 at 05:41
  • Depending on the Version of PHP you are using: `[]` may or may not work. Try: `$cipher->initialize( array( 'driver'=>'openssl', 'key' => $key ) );` instead (since you are using ***PHP 5.3***). – Poiz Nov 16 '16 at 05:41
  • Thanks for the answer Poiz. – Ligthers Nov 16 '16 at 05:43

3 Answers3

27

You are using PHP 5.3. The Array Initialization Construct: [] will not work. Instead, use this approach:

    <?php

        $cipher->initialize(
                array(
                 'driver'=>'openssl',
                 'key' => $key
                )
        );
Poiz
  • 7,611
  • 2
  • 15
  • 17
8

Your PHP version doesn't support [] use array() instead.

1

Don't use [], Use:

 <?php

        $cipher->initialize(
                array(
                 'driver'=>'openssl',
                 'key' => $key
                )
        );
Doruk Ayar
  • 334
  • 1
  • 4
  • 17