Skip to content

re: Don't return associative arrays! VIEW POST


I'm generally only building REST APIs so this is kind of a non-issue for me at present. But I do tend to use type hints as much as possible, and can agree that what you suggest is a nice idea!


When you are building REST APIs, why isn't this an issue for you? Do you have some examples where you can't use value objects over arrays?


Ah, I see what you mean. I was thinking more along the lines that I produce small APIs where I'm the only dev, but now I see it will help me if nobody else. 😊

Always consider that others could be involved in it some day. That helps to reflect your own work and will at least make it easier for you in the end if you have to look at that code after some months.

I personally always set the goal that I want to make a project open source available on github. That means that others will see this piece of code and they want to understand what I'm doing.

Yes, and even if not, it will help me when I have to debug things two months down the road. If I don't have explicit objects to look at, making an API request and examining the JSON is the only way. 😂


Thanks. I definitely recommend using type hinting as it really lets you know quickly if your methods are not receiving or returning the type of data you expect.


Yes, but all this makes me wonder if we shouldn't have all adopted Java. It does almost everything in a better way, and for everything else, there's C++. 😝

Regarding method signatures i think PHP is doing a good job. AFAIK you can pass a null to method in Java instead of an object. That is very weird and stupid imo. PHP throws a TypeError if the type doesn't match.

Don't make me count the warts on PHP. 😝 In the race to stupid, ugly and narrow applications, very few languages can beat PHP. 😬

True. With an important note that the param has to be explicitly defined as nullable.

code of conduct - report abuse