If I try to change the inventory size of a chest with $inv->setSize(0); it doesn't remove the slots. But I can't put stuff in there. So the slot number is 0 but the graphics don't change
this may be a client sided issue, you can try setting these slots to something like red wool named "Inventory Locked"
I can't set the slots. As I said there are only graphical. And I have another question. How can I open a Hopper inventory to a player?
well you may be unable to set it, you could send FAKE items there or you can set it to normal size and make sure all these slot with "slot locked" wool dont get moved anywhere by players i dont know i think it's same as opening a chest, you may have more luck with a new thread for a new question