re: How PHP Type Declarations Actually Work VIEW POST


Even though I sometime use type declarations, I try to prevent myself to start using them in every single scenario. An Example of where I mostly reach for type declarations is this:

public function addEvent(array $data) : Event
   return Event::create($data);

I think in cases like the top one it helps for readability.

I feel sometimes that when I reach for so much type hints and return types, I'm making PHP something more Like Java (And I really don't enjoy Java).

It's just my way of thinking. Totally respect your point of view also. šŸ˜Š


I think this often depends on your code background. I got into PHP after I'd written more strongly typed languages like c#. So I've always felt comfortable around type hints, etc.


then how can you tell what to pass to functions?

$order->pay(new Potato());

lol, your talking like the developer is a kid. Iā€™m expected to have a certain domain over the codebase. šŸ˜

code of conduct - report abuse