Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Q2A Core by

What is the proposal of the pieces of code below and in what situations they are useful?:




    if (@$followanswer['basetype']!='A')

Q2A version: 1.7.0
What do you mean by "proposal"? You want to know what those pieces of code do? Or you want to know what they do in the context in which they actually are?

1 Answer

+4 votes
selected by
Best answer

a) In admin/posting there is this setting: Allow questions to be related to answers​. If it is enabled you'll see another button in the answers that allow to ask a related question. This redirects you to the ask page but adds the follow parameter in the URL. This means you go to the ask page this way: http://www.question2answer.org/qa/ask?follow=44021

The 44021 is the ID of the answer that the question will be related to.

b) If there is a post related to the answer, then it is fetched from the DB, using the ID in $followpostid. The thing is that you don't actually know much about it. Maybe the post didn't exist. Maybe the post is not an answer (it could be, e.g., a question). So you need to be as sure as possible you're doing things the right way.

So, without using the (discouraged) @ operator, these checks can be made this way:

if (!isset($followanswer['basetype']) || $followanswer['basetype'] !== 'A') {
    $followanswer = null;

First condition checks $followanswer is not null and is an array which contains a basetype key, which means the post exists. Second condition checks the post is not an answer. So if any of them are true, then the $followanswer variable is null which means the question is not linked to an answer.