Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse error: syntax error, unexpected '[' How to fix this one? [duplicate]

Tags:

php

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

like image 634
Ligthers Avatar asked Nov 16 '16 05:11

Ligthers


People also ask

How do I fix parse error syntax error unexpected?

A parse error: syntax error, unexpected appears when the PHP interpreter detects a missing element. Most of the time, it is caused by a missing curly bracket “}”. To solve this, it will require you to scan the entire file to find the source of the error.

What is syntax error in PHP?

If the PHP code contains a syntax error, the PHP parser cannot interpret the code and stops working. For example, a syntax error can be a forgotten quotation mark, a missing semicolon at the end of a line, missing parenthesis, or extra characters.

What is meant by parse error in PHP?

Parse Error (Syntax) Parse errors are caused by misused or missing symbols in a syntax. The compiler catches the error and terminates the script. Parse errors are caused by: Unclosed brackets or quotes. Missing or extra semicolons or parentheses.


1 Answers

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
                )
        );
like image 166
Poiz Avatar answered Sep 18 '22 19:09

Poiz