Skip to main content
Topic: fetchQueryCallback (Read 3028 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

fetchQueryCallback

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.

Re: fetchQueryCallback

Reply #1

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).
Bugs creator.
Features destroyer.
Template killer.

Re: fetchQueryCallback

Reply #2

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:-)

Re: fetchQueryCallback

Reply #3

Yeah, but I have it on the other computer that I do not switch on very often... O:-)
Bugs creator.
Features destroyer.
Template killer.

Re: fetchQueryCallback

Reply #4

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);
Bugs creator.
Features destroyer.
Template killer.

Re: fetchQueryCallback

Reply #5

Is the explanation acceptable, or it is better not to have such cases?
Bugs creator.
Features destroyer.
Template killer.

Re: fetchQueryCallback

Reply #6

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.