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

Classes in arrays?

Comments in 'Plugin Development' started by Sensej, Feb 9, 2015.

  1. Sensej
    Offline

    Sensej New Member

    Joined:
    Aug 5, 2014
    Posts:
    64
    Hello when im trying to put a class in an array (for an chest refill plugin) why i couldnt put classes in my array?

    example:

    PHP:
    §this->chest = [new item(101)]
    ?
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Yes you can ;) or you can try using something like "spl_object"
    EvolSoft likes this.
  3. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    PHP:
    private $chests = array();
    $this->chests[] = new SomeClass();
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes you can.
    PHP:
    $this->chest = [new Item(101)];
    Remember to put use pocketmine\item\Item at the front; and 0 and 1 are the default parameters in parameters 2 and 3 of Item constructor, which you can omit if they are 0 and 1.
    What? The only function that starts with spl_object is spl_object_hash(), and it has nothing to do with this thread.
    iksaku and EvolSoft like this.

Share This Page

Advertisement