How to write this? CODE: public function blala(Player $player, array $items, int $id, string $title) { } PHP: // I used this but i gave error.$plugin->blala($player, [1, 2], 54, "Test");
Other devs correct me if I'm wrong, I haven't messed with PHP in a while - but why are you defining types for everything, even strings and numbers? You should just be able to do: PHP: public function blala(Player $player, $items, $id, $title) { // do something}blala($player, array(1,2), 54, 'Test');// $player === $player// $items === array(1,2)// $id === 54// $title === 'Test'
A good practice, sure. But if trying to avoid bugs by using type-hinting is actually causing the bugs... You should at least test it without the type-hinting to see if that fixes it. I've mainly just been doing JS for (almost) a year, so I guess I could be looking at this with slightly different logic to everyone else, but still...
Sorry, I wasn't very clear there. I meant that you should test everything (including without type-hinting) so that you can see what really is causing the bugs, so that you actually can fix those bugs.
Typehinting checks if the value is of that type at runtime. What is the point of testing without typehinting?
Oh. I guess I misunderstood what type-hinting was then... Sorry. The point of testing without type-hinting would be to run it, and log what values are passed to it without type-hinting so you can see what it actually is receiving, and what is being done with what it is receiving. And it would be partly out of curiosity, on my part at least, to see what happens. I would test everything, necessary or not, just to see what things are doing (code rarely does exactly what I expect it to), but that's just me. Others may view things differently ¯\_(ツ)_/¯ Since the OP hasn't given us the error yet, that may or may not help. Just suggesting what I could from my limited knowledge/experience. The error is probably to do with something inside that function, not the type-hinting, but all he gave us was the type-hinting...