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

3
  • You're using a version of PHP that does not support new array initialization syntax Commented Nov 16, 2016 at 5: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
    Commented Nov 16, 2016 at 5:41
  • Thanks for the answer Poiz.
    – Ligthers
    Commented Nov 16, 2016 at 5:43

3 Answers 3

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
                )
        );
8

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

1

Don't use [], Use:

 <?php

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.