Question

I'm trying to generate my database via Laravel's migration files, but when I try to do so I get the following error:

PHP Parse error:  syntax error, unexpected '[', expecting ')' in D:\wamp24\www\laravel\app\controllers\SomeController.php

This is driving me crazy, I can run the migration files when I comment out the code in my controllers, but I can't keep on doing this.

I also don't want to rewrite all my code, since I use the square brackets almost everytime I declare an array (using the square brackets is a lot quicker than typing 'array( ~ )' ... )

I'm using PHP 5.3.13 on a wampserver (2.4) with apache 2.2.22 on Win 8.1.

Laravel Framework version 4.0.10.

The code that gives the error is the following:

class SomeController extends BaseController {
    public function someFunc() {
        $var= Model::create([
            'title' => Input::get('title'),
            'description' => Input::get('description'),
        ]);
    }
}

Anyone who knows a solution to this error?

Was it helpful?

Solution

It's because your PHP version doesn't support [] array syntax, try:

$var = Model::create(array(
    'title' => Input::get('title'),
    'description' => Input::get('description')
));

It is not supported in PHP < 5.4. Upgrade your PHP version or use array() instead of [].

OTHER TIPS

I think it has to do with formatting.

Try:

class SomeController extends BaseController {
public function someFunc() {
    $var= Model::create(array(
        'title' => Input::get('title'),
        'description' => Input::get('description'),
    ));
  }
}

That should work.

php 5.3.x not support short array , try to change it like this

Model::create(array(
            'title' => Input::get('title'),
            'description' => Input::get('description')
    ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top