1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Not a Bug Extra data constant - boleans error

Discussion in 'Resolved Bug Reports' started by cclaerhout, Jun 20, 2013.

  1. cclaerhout

    cclaerhout Well-Known Member

    First of all, I'm not sure it's a bug or if it's the expected behaviour.

    In the datawriter when we want to set a constant to be used after as an "extra data" it can't be anymore a boolean. If it is, when we use the function "getExtraData" the php function array_key_exists of the xenforo datawriter function "isExtraDataSet" is not going to like it:
    Can it be changed or do I have to modify the way I'm using the constant?
     
  2. Mike

    Mike XenForo Developer Staff Member

    Am I understanding this right, that you're effectively doing this?
    Code:
    $extraDataKey = true;
    $dw->getExtraData($extraDataKey);
    That doesn't really make sense to me - it's a key so by definition it needs to be a string or an integer (probably a string).
     
  3. cclaerhout

    cclaerhout Well-Known Member

    May be I don't use it correctly, but I've just tried to use a pattern I've found a few month ago on XenForo files but with a bolean and not a string.

    Example:

    > Extended Datawriter:
    PHP:
     const ALLOW_OVERRIDE false;
    > In the same Extended Datawriter but in a function this time:
    PHP:
    $canOverride $this->getExtraData(self::ALLOW_OVERRIDE);
    > And in my controller (admin):
    PHP:
    $dw->setExtraData(myClass::ALLOW_OVERRIDEtrue);
     
  4. Despair

    Despair Active Member

    Maybe you could use an option in this case. In your datawriter:
    PHP:
    const OPTION_ALLOW_OVERRIDE 'allowOverride';

        protected function 
    _getDefaultOptions()
        {
            return array(
                
    self::OPTION_ALLOW_OVERRIDE => false,
            );
        }
    PHP:
    $canOverride $this->getOption(self::OPTION_ALLOW_OVERRIDE);
    PHP:
    $dw->setOption(myClass::OPTION_ALLOW_OVERRIDEtrue);
     
    Bob, xf_phantom and cclaerhout like this.
  5. cclaerhout

    cclaerhout Well-Known Member

    @Despair, I've initially thought of another workaround but yours seems far more professional. I'm going to test it. Thanks!
     
  6. cclaerhout

    cclaerhout Well-Known Member

    @Despair, I confirm, it's working great :)
     
    Despair likes this.
  7. Despair

    Despair Active Member

    I just follow the way XF does things, so if it's professional I don't take credit for that. :p
     
    cclaerhout likes this.
  8. Mike

    Mike XenForo Developer Staff Member

    Just for reference, when you define this:
    Code:
    const ALLOW_OVERRIDE = false;
    You're not defining a name value pair. You're defining self::ALLOW_OVERRIDE / ClassName::ALLOW_OVERRIDE to be false. It's really just an unchangeable variable.

    In this case, the define is used as a key (rather than a value), so that doesn't really make sense.

    It's worth noting that the only reason we use defines is it creates a form of documentation as to the potential extra data/options available to a datawriter.
     
    cclaerhout likes this.
  9. cclaerhout

    cclaerhout Well-Known Member

    The first sentence was quite out of my league but the two others are very clear. Thank you for your explanation.
     

Share This Page