Reputation: 19
I have some experience with php, but I just saw a syntax (Yii2 reference) I'm not sure how to read and couldn't find explicitly in the docs. What does the "[new" mean? Does this define an array of new objects?
public function actionCreate()
{
$model = new Credit();
$modelReferences = [new CreditRefence()];
$modelFiles = [new CreditFile()];
Upvotes: 0
Views: 57
Reputation: 133380
The new is for create a new object/model in this case you are creating 3 object Credit, CreditRefence, CreditFile
the first is assingne $model a simple var
the other are assigned to array .. [] is the new shortcut sintax for array in php 5.4
In your application probably you have Credit, CreditRefence, CreditFile in model
Upvotes: 0
Reputation: 2300
As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].
Source: http://php.net/manual/en/language.types.array.php
Upvotes: 1