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

Traits Help

Comments in 'Plugin Development' started by PEMapModder, Jun 15, 2014.

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How do you call the parent constructor in a subclass of a trait?
    For example,
    PHP:
    trait Bar{
        public function 
    __construct($name){
            
    // blah blah blah
        
    }
    }
    class 
    Foo{
        use 
    Bar;
        public function 
    __construct(Player $player){
            
    // how do you give $player->getName() to Bar parent?
        
    }
    }
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I didn't think traits used a construct method. But you can call functions in inherited traits using $this->function_name(). I am not sure if this answers your question.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I tried using MyTrait::__construct() but it was rejected by PHPStorm.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I did some StackOverflow searching and found this:
    PHP:
    class MyHelloWorld extends Base {
        use 
    SayWorld {
            
    SayWorld::__construct as private __swConstruct;
        }

        public function 
    __construct($a$b$c 0)
        {
            
    $this->__swConstruct($a$b$c);
        }
    }
    PEMapModder likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Thanks I'll check :) it is for xEcon.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Can you give me the link to it?
  7. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    PEMapModder likes this.

Share This Page

Advertisement