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. Offline

### SensejNew 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(1, 0, 1)] 
?
2. Offline

### iksakuNotable MemberPlugin Developer

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

### Sergey_DActive Member

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

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,293
Plugins:
11
Minecraft User:
Yes you can.
PHP:
 \$this->chest = [new Item(1, 0, 1)]; 
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.