0

If i read a struct(storage) Human storage human = humans[2]; in my modifier is there a possibility that the function that uses this modifier can use the "human"? Otherwise i have to scope the storage again in my function.

  • 1
    Your question is unreadable. Please post the relevant code (function, state variable and modifier) properly. – goodvibration Feb 10 at 13:23
2

is there a possibility that the function that uses this modifier can use the "human"

No. Nothing scoped in a modifier is available in a modified function.

Otherwise i have to scope the storage again in my function.

Right.

Simple example with memory variable:

pragma solidity 0.5.1;

contract Scope {

    modifier checkScope {
        uint x = 100;
        _;
    }

    function doSomething() public pure checkScope returns(uint) {
        //return x; // can't use it
    }
}

Or more like your code:

pragma solidity 0.5.1;

contract Scope {

    struct Human {
        bool b;
    }

    Human[] humans;

    modifier checkScope {
        Human storage human = humans[2];
        _;
    }

    function doSomething() public view checkScope returns(bool) {
        // return human.b; // will not compile
        return humans[2].b; // works
    }
}

Hope it helps.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.