ElkArte Community

Elk Development => Bug Reports => Topic started by: Joshua Dickerson on October 14, 2015, 09:56:24 pm

Title: fetchQueryCallback
Post by: Joshua Dickerson on October 14, 2015, 09:56:24 pm
fetchQueryCallback() gives an error in my IDE because the if($callback === null) part isn't seen. It doesn't make sense to allow the callback to be null. I think the best way to do it would be to change it to

Code: [Select]
public function fetchQueryCallback($db_string, Callable $callback, array $db_values = array(), array $seeds = array())

Before I go committing that change, I wanted to know what you guys think.
Title: Re: fetchQueryCallback
Post by: emanuele on October 15, 2015, 02:22:25 am
I guess the null would indeed be meaningless.
Does your IDE point to any specific place where the function is called with a null argument? (Just to be sure there isn't any edge-case I forgot about).
Title: Re: fetchQueryCallback
Post by: Spuds on October 15, 2015, 05:52:22 am
Quote from: emanuele – I guess the null would indeed be meaningless.
Does your IDE point to any specific place where the function is called with a null argument? (Just to be sure there isn't any edge-case I forgot about).
You have the same one lazy O:-)
Title: Re: fetchQueryCallback
Post by: emanuele on October 15, 2015, 08:14:23 am
Yeah, but I have it on the other computer that I do not switch on very often... O:-)
Title: Re: fetchQueryCallback
Post by: emanuele on March 24, 2016, 03:50:45 am
I'm a bit dumb at times, I didn't get the message right, now I do.
Yep, I added the null default more or less to mimic the jQuery behaviour: if there is a callback call it, otherwise just do what you are supposed to do with it. The cheap polimorphism you can achieve with PHP.

ETA: a potential case (as of now, not existing):
Code: [Select]
if (condition) {
    $query = 'SELECT * FROM something LEFT JOIN somethingelse';
    $callback = function ($vals) {...};
}
else {
    $query = 'SELECT * FROM something';
    $callback = null;
}

$results = $db->fetchQueryCallback($query, $values, $callback);
Title: Re: fetchQueryCallback
Post by: emanuele on April 23, 2016, 12:24:05 pm
Is the explanation acceptable, or it is better not to have such cases?
Title: Re: fetchQueryCallback
Post by: Joshua Dickerson on April 23, 2016, 01:25:32 pm
Why use a method that does a callback if there is no callback? Just call fetchQuery() and if you want to use a callback, call fetchQueryCallback(), or just have fetchQuery($query, array $values, $callback = null). I don't have Elkarte open and I don't have much time (working on learning how to add modules for PuPHPet) and then a wedding later.