Fetch/Join Options

Naz

XenForo developer
Staff member
Just a question regarding fetch/join options.

At the top of XenForo_Model_Thread there is this:

PHP:
const FETCH_USER = 0x01;
const FETCH_FORUM = 0x02;
const FETCH_FIRSTPOST = 0x04;
const FETCH_AVATAR = 0x08;
const FETCH_DELETION_LOG = 0x10;
const FETCH_FORUM_OPTIONS = 0x20;

From my understanding, these constants are used to identify what other information should be pulled with the thread information. I was wondering if someone could provide a bit more insight as to how this all works as I'm a little confused. Like for example, FETCH_USER = 0x01. Is there any significance to that value or is it random?
 
Code:
if (!empty($fetchOptions['join']))
        {
            if ($fetchOptions['join'] & self::FETCH_CATEGORY)
            {
                $selectFields .= ',
                    category.*, category.last_update AS category_last_update, resource.last_update';
                $joinTables .= '
                    LEFT JOIN xf_resource_category AS category ON
                        (category.resource_category_id = resource.resource_category_id)';
            }
Some CMD+Click did the trick to find the above code.

I think those are just random HEX. Instead of putting 1, 2, 4, 8 they have converted the decimals into their hex form.
Most probably they have used it for performance reasons(I might be wrong here), since it's easier for computers to go from HEX to Binary than Decimal to Binary.

PS: I just read on stackoverflow
It's a matter of taste. For one, using hexadecimal makes the constants line up nicely, and they are less typing.

Plus it looks cool.
 
  • Like
Reactions: Naz
Code:
if (!empty($fetchOptions['join']))
        {
            if ($fetchOptions['join'] & self::FETCH_CATEGORY)
            {
                $selectFields .= ',
                    category.*, category.last_update AS category_last_update, resource.last_update';
                $joinTables .= '
                    LEFT JOIN xf_resource_category AS category ON
                        (category.resource_category_id = resource.resource_category_id)';
            }
Some CMD+Click did the trick to find the above code.

I think those are just random HEX. Instead of putting 1, 2, 4, 8 they have converted the decimals into their hex form.
Most probably they have used it for performance reasons(I might be wrong here), since it's easier for computers to go from HEX to Binary than Decimal to Binary.

PS: I just read on stackoverflow
Makes sense. Thank you.
 
Back
Top Bottom