2 deleted 1 character in body
source | link

general

The first way creates an object of type EntryQuery, you then call the 2 functions section and limit

In PHP you would do the following:

$query = Entry::find()->section('news')->limit(10);

The second creates an array section => 'news', 'limit' => 10 you then call Yii2::configure($query, $array) with your EntryQuery which does:

public static function configure($object, $properties)
{
    foreach ($properties as $name => $value) {
        $object->$name = $value;
    }

    return $object;
}

Thus you don't call functions but define the properties directly. In PHP it would look like

$query = Entry::find();
Craft::configure($query, ['section' => 'news', 'limit' => 10]);

Performance

Because of the above it's important what you do. The first way calls functions the second way calls properties.

As for your comparison the first way is a little bit faster because you didn't attach functions that requires the use of magic methods => __call (in the ElementQueryBehavior) as soon as you search/filter for custom fields the Craft::configure way will always be a little bit faster because it can set the values directly instead of using the resource heavy __call function

For example:

// faster
$query = Entry::find()
    ->section('news')
    ->limit(10)

// slower
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news', 
    'limit' => 10
]);

Against

// slower
$query = Entry::find()
    ->section('news')
    ->limit(10)
    ->multiselect('test')
    ->subline('foo');

// faster
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news',
    'limit' => 10,
    'multiselect' => 'test',
    'subline' => 'foo'
]);

ConclustionConclusion

Keep in mind when I say "slower" or "faster" I'm talking about a few milliseconds (when I run the last example 1000 times its 511ms vs 497ms) so in the end it does not really matter. If it's really important in terms of speed: as soon as you use the __call method because you need to change properties in the ElementQueryBehavior you would prefer to use Craft::configure.

Besides that: there is absolutely no difference between those two.. There are no hidden "benefits" you don't have more options, you can't do something "better"

general

The first way creates an object of type EntryQuery, you then call the 2 functions section and limit

In PHP you would do the following:

$query = Entry::find()->section('news')->limit(10);

The second creates an array section => 'news', 'limit' => 10 you then call Yii2::configure($query, $array) with your EntryQuery which does:

public static function configure($object, $properties)
{
    foreach ($properties as $name => $value) {
        $object->$name = $value;
    }

    return $object;
}

Thus you don't call functions but define the properties directly. In PHP it would look like

$query = Entry::find();
Craft::configure($query, ['section' => 'news', 'limit' => 10]);

Performance

Because of the above it's important what you do. The first way calls functions the second way calls properties.

As for your comparison the first way is a little bit faster because you didn't attach functions that requires the use of magic methods => __call (in the ElementQueryBehavior) as soon as you search/filter for custom fields the Craft::configure way will always be a little bit faster because it can set the values directly instead of using the resource heavy __call function

For example:

// faster
$query = Entry::find()
    ->section('news')
    ->limit(10)

// slower
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news', 
    'limit' => 10
]);

Against

// slower
$query = Entry::find()
    ->section('news')
    ->limit(10)
    ->multiselect('test')
    ->subline('foo');

// faster
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news',
    'limit' => 10,
    'multiselect' => 'test',
    'subline' => 'foo'
]);

Conclustion

Keep in mind when I say "slower" or "faster" I'm talking about a few milliseconds (when I run the last example 1000 times its 511ms vs 497ms) so in the end it does not really matter. If it's really important in terms of speed: as soon as you use the __call method because you need to change properties in the ElementQueryBehavior you would prefer to use Craft::configure.

Besides that: there is absolutely no difference between those two.. There are no hidden "benefits" you don't have more options, you can't do something "better"

general

The first way creates an object of type EntryQuery, you then call the 2 functions section and limit

In PHP you would do the following:

$query = Entry::find()->section('news')->limit(10);

The second creates an array section => 'news', 'limit' => 10 you then call Yii2::configure($query, $array) with your EntryQuery which does:

public static function configure($object, $properties)
{
    foreach ($properties as $name => $value) {
        $object->$name = $value;
    }

    return $object;
}

Thus you don't call functions but define the properties directly. In PHP it would look like

$query = Entry::find();
Craft::configure($query, ['section' => 'news', 'limit' => 10]);

Performance

Because of the above it's important what you do. The first way calls functions the second way calls properties.

As for your comparison the first way is a little bit faster because you didn't attach functions that requires the use of magic methods => __call (in the ElementQueryBehavior) as soon as you search/filter for custom fields the Craft::configure way will always be a little bit faster because it can set the values directly instead of using the resource heavy __call function

For example:

// faster
$query = Entry::find()
    ->section('news')
    ->limit(10)

// slower
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news', 
    'limit' => 10
]);

Against

// slower
$query = Entry::find()
    ->section('news')
    ->limit(10)
    ->multiselect('test')
    ->subline('foo');

// faster
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news',
    'limit' => 10,
    'multiselect' => 'test',
    'subline' => 'foo'
]);

Conclusion

Keep in mind when I say "slower" or "faster" I'm talking about a few milliseconds (when I run the last example 1000 times its 511ms vs 497ms) so in the end it does not really matter. If it's really important in terms of speed: as soon as you use the __call method because you need to change properties in the ElementQueryBehavior you would prefer to use Craft::configure.

Besides that: there is absolutely no difference between those two.. There are no hidden "benefits" you don't have more options, you can't do something "better"

1
source | link

general

The first way creates an object of type EntryQuery, you then call the 2 functions section and limit

In PHP you would do the following:

$query = Entry::find()->section('news')->limit(10);

The second creates an array section => 'news', 'limit' => 10 you then call Yii2::configure($query, $array) with your EntryQuery which does:

public static function configure($object, $properties)
{
    foreach ($properties as $name => $value) {
        $object->$name = $value;
    }

    return $object;
}

Thus you don't call functions but define the properties directly. In PHP it would look like

$query = Entry::find();
Craft::configure($query, ['section' => 'news', 'limit' => 10]);

Performance

Because of the above it's important what you do. The first way calls functions the second way calls properties.

As for your comparison the first way is a little bit faster because you didn't attach functions that requires the use of magic methods => __call (in the ElementQueryBehavior) as soon as you search/filter for custom fields the Craft::configure way will always be a little bit faster because it can set the values directly instead of using the resource heavy __call function

For example:

// faster
$query = Entry::find()
    ->section('news')
    ->limit(10)

// slower
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news', 
    'limit' => 10
]);

Against

// slower
$query = Entry::find()
    ->section('news')
    ->limit(10)
    ->multiselect('test')
    ->subline('foo');

// faster
$query = Entry::find();
Craft::configure($query, [
    'section' => 'news',
    'limit' => 10,
    'multiselect' => 'test',
    'subline' => 'foo'
]);

Conclustion

Keep in mind when I say "slower" or "faster" I'm talking about a few milliseconds (when I run the last example 1000 times its 511ms vs 497ms) so in the end it does not really matter. If it's really important in terms of speed: as soon as you use the __call method because you need to change properties in the ElementQueryBehavior you would prefer to use Craft::configure.

Besides that: there is absolutely no difference between those two.. There are no hidden "benefits" you don't have more options, you can't do something "better"