0

Today I hammered closed a question where the requirements are the same as the target:

Is there a mysqli_fetch_all() equivalent to return an array of objects?

The new question was asked recently, while the duplicate target was asked in 2012.

@Dharman posted an answer on the new question before I hammered.

I happened to return to the page later in the same day to find that @YourCommonSense un-hammered the question with no explanation and edited the duplicate target question.

I find the action of unhammering in this case to be deliberately undermining the work of closing duplicates.

@Phil then posted an answer on the new question after it was reopened.

Since there is currently no green tick on the new question, there is no reason why both answerers can't simply move their answers to the earlier page.

I asked @Dharman to re-hammer the new question or merge it with the target, but he refused.

This feels like an injustice to the Help Center's explanation of closing duplicate questions:

The fundamental goal of closing duplicate questions is to help people find the right answer by getting all of those answers in one place.

What do you think should happen?

13
  • 2
    TBH, I don't see how your assumption on their voting behaviour is related to the problem here. If, however, someone believes that a duplicate candidate is not useful/helpful and thus reopens the question, downvoting those duplicates (as they perceive them not useful/helpful) does seem correct behaviour; that is, afterall, what votes are for.
    – Thom A
    Commented Aug 19, 2022 at 12:52
  • 4
    It also seems that Dharman engaged you in chat and explained their reasoning. I feel it very one-sided to omit their arguments, especially as they took the time to do so (many users would not, moderator or not).
    – Thom A
    Commented Aug 19, 2022 at 12:53
  • I've added the link to the question sorry. The dialogue between Dharman and myself is available in the chat link on the page. Commented Aug 19, 2022 at 12:56
  • 12
    "The dialogue between Dharman and myself is available in the chat link on the page." It is, but I feel that just saying "they refused" is a little disingenuous. They didn't so much refuse, but instead stated that it wouldn't be right for them to do so as they are already involved in the question, and also offered reasons as to why the other question isn't a good candidate. They discussed the problem with you, they didn't refuse you.
    – Thom A
    Commented Aug 19, 2022 at 12:58
  • 2
    The end result was a refusal. I wanted to keep the question relatively short because MSO seems to hate my mile-long questions. @Larnu Commented Aug 19, 2022 at 13:21
  • 5
    The edit by Your Common Sense is to change the title... in a way that, to me, makes it pretty clear why the question is not a duplicate. The old question simply sought a way to get all the rows as one result, and was satisfied by the row results being associative arrays. The new question is specifically about looking for a different version of the thing that gets the associative-array result, in order to get an object result instead (without manual iteration). The new answers indicate that this is not supported. Commented Aug 19, 2022 at 14:02
  • Fortunately for the case that I am pleading, @Dharman himself believes that questions do not need to be identical but that one answer on the dupe target needs to contain the resolving advice for the closed page. I don't have a problem with this stance; afterall, signposts are good when they ask differently for the same resolving advice. Signposts are bad when they ask the same question in exactly the same way. Commented Aug 20, 2022 at 11:07
  • @Karl that is an incorrect read of the old question. Not only did the asker demonstrate that pushing objects into a result array in a loop provides the desired structure, the asker literally asked if there is a single call like $result->fetch_objects(). Both questions are seeking the exact same resultant structure. I explain this in my answer below. Commented Aug 20, 2022 at 22:48
  • 1
    The whole system of duplicate questions on SO serves SEO reason. Engines use the canonical link and humans will follow to the higher effort content. Considering the amount of content on SO, with content very similiar yet different on a very fine level, it gets difficult to recognize for robots and humans fine variations. IMO, it's healthy SEO diversity to have similiar threads in parallel. It allows the reader to compare the topics and do an inner A/B test on the content. I'm not ready to take any side on this, I think Dharman said something good and it went like "what do we gain from it".
    – Daniel W.
    Commented Aug 21, 2022 at 3:42
  • @DanielW I believe Dharman was questioning what was to gain from merging. I was offering page merging as a fallback option after rehammering was refused. SO and its researchers will be best served if all answers are transferred to the older page and the positively scored signpost points all researchers to where ALL of the answers are. When all answers are on one page, the scoring and sorting feature is able to indicate which answers are best/worst. It is a win for EVERYONE if Dharman's answer is moved to the old page and the new page is its signpost. Commented Aug 21, 2022 at 3:47
  • While I think "row" is certainly more specific/clear than "object", the answers on the duplicate target are about objects (e.g. answers talk about objects over arrays). I'm not a MySQL SME (or even user anymore) so I'm not sure if the edit invalidates any of the remaining answers in that regard.
    – TylerH
    Commented Aug 26, 2022 at 14:57
  • @TylerH There will be hundreds if not thousands of PHP/MySQLI mysqli pages on Stack Overflow that ask about fetching "rows" of data. What differentiates the older question from the majority of other pages is that the asker wants to receive the rows of data as objects (not assoc or indexed arrays). Even "row" suggests an indexed array. php.net/manual/en/mysqli-result.fetch-row.php The title absolutely should contain the vital keyword "objects" to best identify the question and aid researcher discovery. Ask yourself: if you were the new asker, would the old Q's answer resolve your Q? Commented Aug 26, 2022 at 22:16
  • Update: the page in question was merged by CodyGray on 16 Feb 2023 into the dupe target that I initially offered. A sensible and favorable resolution. Commented May 17, 2023 at 8:00

2 Answers 2

5

These questions are similar but they are not answered in the same way, so they cannot be considered duplicates.

Donning my hazmat suit since we're dealing with PHP (I kid, although I saw enough of the language in high school), we take a look at your dupe target. In this, the OP is asking how to iterate over a list of results without using a loop construct, to which the answer is apparently to use $result->fetch_all().

To the more recent question, the OP is asking if they can use fetch_all to get back a list objects instead of bringing back an associative array, which is what would normally be returned. The answer to that is apparently "no, use PDO to accomplish this".

What do you think should happen?

I think that the newer question should stay open. It's most certainly not related to your dupe target, since it's asking about two different circumstances.

4
  • 4
    "Can I use Mysqli::fetch_all() to do x?" "No, you have to use PDO." vs "How can I do x using Mysqli?" "You can't, you have to use PDO." Both questions and answers seem pretty similar to me. Technically they're different but in practical terms they're both asking the same thing.
    – miken32
    Commented Aug 20, 2022 at 3:21
  • 1
    So you're saying it's not a dupe because the old question never clearly says that they want an array of objects? It seems to be implied because they user fetch_object() in the loop and then say they're looking for something that might be called fetch_objects(). @mickmackusa seems to have taken this as implicitly asking for the same thing as the new question.
    – Barmar
    Commented Aug 20, 2022 at 15:20
  • 1
    But even if the questions aren't exactly the same, the answer is applicable. It says that fetch_all() is the only way to get all the rows at once, and enumerates the format of results it returns. This answers the original question (the answer is "no").
    – Barmar
    Commented Aug 20, 2022 at 15:23
  • 1
    @miken32 The second question is not "How can I do x using MySQLi", it's "How can I do y in MySQLi", and the answer is "This way. But if you want y to be in x form, you have to use PDO". That is why they are slightly different.
    – TylerH
    Commented Aug 26, 2022 at 15:01
2

Irrespective of @YourCommonSense's change of "object" to "row" in the title (which I feel makes the title less specific in an unhelpful way), the dupe target is asking how to fetch the entire result set as an array of objects.

@oaziz explains in the question that they already know how to fetch a single row as a flat object with fetch_object(). Then they explain that they are currently using a fetch_object() inside of a while() loop to generate the desired array of objects. Then they ask if mysqli has a more direct way to fetch all rows as an array of objects -- something like fetch_objects().

This question is very clearly asking if php/mysqli offers a native way to fetch all rows as an object array.


The new question from @AbdulwahabAlmestekawy is using the procedural syntax (mysqli_fetch_object) in a loop to make an array of objects and is also asking if php/mysqli offers a native way to generate an array of objects from the result object.


Because both questions are clearly asking for the exact same technique/result, closure is appropriate.

  • The new Q wants $arr_objects as an array of objects.
  • The old Q wants $comments as an array of objects.

The answer from @pilcrow is correct, appropriate, and is the top sorted answer -- this makes good advice easy to find when researchers arrive at the page. The dupe target is not "bad" for researchers. If editing the question will improve its searchability, I would support that (I may end up doing an edit after this meta discussion cools down anyhow).

I find @KyleNoland's answer to be too distant from resolving the asked question. I have voted to delete this unhelpful answer.

As I mentioned in my chat conversation with @Dharman, I often find suitable dupes to close new questions where the dupe target does not contain what I feel is the "best" answer -- this does not prevent me from closing the new question. In fact, I like finding older pages where the insights are suboptimal -- it means that I finally found a question that I can post an answer on. In these situations, I close the new page, answer the dupe target with suitable clarity/explanation to resolve both questions, then proceed to edit the question and critique all other answers/comments on the page to best serve future researchers.

@Dharman's advice is 100% suitable on the dupe page without any adjustment. I'd argue that it would become the new "best" answer on the dupe target.

@Phil's answer on the new question is less helpful since it is a looped/non-native equivalent of the asker's code, but it too could be safely transferred to the dupe target.

After @YourCommonSense reopened the page, I knew I could not rehammer, so I asked if @Dharman would rehammer or even merge the two identical pages. He refused because he was involved in the new page as an answer (obviously) and didn't want to appear unethical.

I believe the best outcome for the new page would be that:

  1. The question remain positively scored to become a signpost for the dupe target.
  2. @Dharman delete his answer on the new page, post it as an answer on the dupe target, then close the new page.
  3. @Phil's answer, too, can be deleted and posted on the dupe page.

This is a better outcome than merging the pages (which is a bit of a kludge) because the one topic now retains two access points for researchers and all answers would be in one place so that scores and sorting are simplest for researchers.

There is nothing stopping anyone from doing this immediately because:

  1. There is no green tick on the new question.
  2. @Dharman will no longer appear unethical for hammering a page where he has answered.

None of these actions do harm or punish any users. These actions prioritize Stack Overflow content curation for the betterment of the Researcher eXperience. If I were in @Dharman's position I would take the earlier described actions myself without any prompting. It just makes logical sense to me. Not #SOReadyToHelp but #ReadyToHelpSO

7
  • I remain unpersuaded on your explanation that these questions are "clearly" asking for the same thing. Asking how to get all results from an SQL call is not the same as mapping all results to an object from an SQL call. Note too that I'm a very disinterested party; I have the interest of the site in mind and I want to see that these things work out in the best interest of the asker and curators. With that in mind and with the aforementioned, I don't see how your proposed solution fixes anything besides makes you happy that you were able to hammer a question (that shouldn't be).
    – Makoto
    Commented Aug 19, 2022 at 22:08
  • 1
    Pfft. I find MSO unsurprisingly and irritately unhelpful. Both questions are literally seeking an array of objects in one call. If you can't see that truth, I don't know how to explain it to you any clearer. New question: "get the entire result set of a mysqli select statement in one call [...] but as an array of objects" and Old question: "$result->fetch_objects()" Commented Aug 19, 2022 at 23:47
  • Hey, don't bite my head off. I don't care about PHP, like at all. I just don't think this is a duplicate and I don't see how your explanation of how it is assuages my skepticism.
    – Makoto
    Commented Aug 19, 2022 at 23:51
  • 1
    Well, for an uninterested party, you are supporting the fracturing of content. I really expected a more collaborative and system-centric response from all veteran users involved in the scenario and discussion. This is one more straw on the back of the camel where I hang up my hammer and stop wasting my time with curation. I should just start GordonLinoff'ing every dupe I find instead of voting to close. Commented Aug 19, 2022 at 23:54
  • 1
    Your explanation of why these are dupes focuses on the mechanics of how data is retrieved from the database, not the intent of what to do with that data, which is where I draw the distinction. If you want to collaborate, be more open to feedback when someone disagrees with your perspective as opposed to taking whatever action "Gordon Linoff'ing" happens to be.
    – Makoto
    Commented Aug 19, 2022 at 23:55
  • 1
    I think I am being equally open as the other users involved. GordonLinoff'ing is where you answer questions that you know are duplicates and most of the time, you have answered them before - yourself. Hundreds of Stack Overflow pages with much looser identicality are closed and stay closed everyday. I only see the current state of this situation to be an obvious injustice to the ultimate goal of this site. Commented Aug 19, 2022 at 23:57
  • 2
    It isn't only Gordon Linoff. Look, for example, at the regulars in the Pandas tag (at least one has more than 500,000 reputation points). Questions are never closed there. The same kind of auto-generated homework questions are now also appearing in the R tag (I don't know if they are treated the same way or not). Commented Aug 20, 2022 at 8:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .