<h3>general</h3>

<p>The first way creates an object of type <code>EntryQuery</code>, you then call the 2 <strong>functions</strong> <code>section</code> and <code>limit</code></p>

<p>In PHP you would do the following:</p>

<pre><code>$query = Entry::find()-&gt;section('news')-&gt;limit(10);
</code></pre>

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

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

    return $object;
}
</code></pre>

<p>Thus you <strong>don't</strong> call functions but define the <strong>properties</strong> directly. In PHP it would look like</p>

<pre><code>$query = Entry::find();
Craft::configure($query, ['section' =&gt; 'news', 'limit' =&gt; 10]);
</code></pre>

<h3>Performance</h3>

<p>Because of the above it's <strong>important</strong> what you do. The first way calls <strong>functions</strong> the second way calls <strong>properties</strong>. </p>

<p>As for your comparison the first way is a little bit faster because you didn't attach functions that requires the use of <code>magic methods</code> => <code>__call</code> (in the <code>ElementQueryBehavior</code>) as soon as you search/filter for custom fields the <code>Craft::configure</code> way will always be a little bit faster because it can set the values directly instead of using the resource heavy <a href="http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods" rel="nofollow noreferrer">__call</a> function</p>

<p>For example:</p>

<pre><code>// faster
$query = Entry::find()
    -&gt;section('news')
    -&gt;limit(10)

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

<p>Against</p>

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

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

<h3>Conclusion</h3>

<p>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 <code>__call</code> method because you need to change properties in the <code>ElementQueryBehavior</code> you would prefer to use <code>Craft::configure</code>.</p>

<p>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"</p>

CC BY-SA 4.0
2018-05-07T18:43:22.113Z
2018-05-07T18:59:07.633Z
2018-05-07T18:59:07.633Z
Robin Schambach
<p>I apologize if this has been asked or addressed already, but I have a question concerning Element Queries. The docs show two possible ways: </p>

<p>Chained Methods</p>

<pre><code>{% set query = craft.entries()
    .section('news')
    .limit(10) %}
</code></pre>

<p>Batch-set Parameters</p>

<pre><code>{% set query = craft.entries({
    section: 'news',
    limit: 10
}) %}
</code></pre>

<p><strong>The examples shown above (from the docs) obviously accomplish the exact same thing--but what is the difference, if any?</strong></p>

<p>It is my assumption that the batch-set way of querying elements allows for more options, is that true? And does either way have an effect on performance?</p>

<query><elementquery>
Difference between chained and batch element queries?
# Difference between chained and batch element queries?

(Asked by: username_0 on 2018-05-07)

I apologize if this has been asked or addressed already, but I have a question concerning Element Queries. The docs show two possible ways: 
Chained Methods
{% set query = craft.entries()
    .section('news')
    .limit(10) %}

Batch-set Parameters
{% set query = craft.entries({
    section: 'news',
    limit: 10
}) %}

The examples shown above (from the docs) obviously accomplish the exact same thing--but what is the difference, if any?
It is my assumption that the batch-set way of querying elements allows for more options, is that true? And does either way have an effect on performance?

**Tags:** query, elementquery

---

## 1 answers

### Answer by username_1 on 2018-05-07. Score: 3 | Accepted answer

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"


---

