Crell,
@Crell@phpc.social avatar

Let's be controversial: In modern , you should never type-hint an array.

https://peakd.com/php/@crell/php-never-type-hint-on-arrays

heiglandreas,
@heiglandreas@phpc.social avatar

@Crell Why would you hint for something that you don't use? 😇

Though: As long as PHP doesn't understand stdClass[] as a type, I'd probably still want to have that. And iterable as type isn't better than array in that case...

But I'm usually using self-defined lists-classes in those cases anyhow, so 🤷

timwolla,
@timwolla@phpc.social avatar

@Crell You also shouldn't call it “hint”, no matter if it's an array or something else 😜 (unless you're dealing with PHPDoc, i.e. lies).

Crell,
@Crell@phpc.social avatar

@timwolla Also true. 🙂

Hipska,
@Hipska@mastodon-belgium.be avatar

@Crell “An IDE can provide auto-completion for the properties you've defined.” @phpstorm can do that for the returned array as well if you put it in phpdocs.

Crell,
@Crell@phpc.social avatar

@Hipska @phpstorm Oh good, so provide the structure in a totally different syntax that the engine cannot lint for you (a separate tool is needed), and can easily get out of sync without errors. And uses twice the memory of a class.

I'll take native types, thanks.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • php
  • Durango
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • khanakhh
  • InstantRegret
  • Youngstown
  • ngwrru68w68
  • slotface
  • rosin
  • tacticalgear
  • mdbf
  • kavyap
  • modclub
  • megavids
  • osvaldo12
  • ethstaker
  • cubers
  • normalnudes
  • everett
  • tester
  • GTA5RPClips
  • Leos
  • cisconetworking
  • provamag3
  • anitta
  • JUstTest
  • lostlight
  • All magazines