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

adam_turcsan,
@adam_turcsan@phpc.social avatar

@Crell I would say that this article is meant to be controversial and deliberately ignore nuances :P But there are some cases for example around serialization where a complex array shape as a typehint helps a lot during static analysis. Turning db data, API requests or responses into objects can be so much easier and transparent if you do it with arrays, array shapes and proper static analysis.

Crell,
@Crell@phpc.social avatar

@adam_turcsan Only if you lack a proper serializer, like Crell/Serde.

adam_turcsan,
@adam_turcsan@phpc.social avatar

@Crell I was using Valinor for some time, but covering some non-trivial cases seemed to be more pain then it should have. Creating fromArray static factories and toArray methods with proper array shape doesn't seem like an "unproper" serialization.

Tylae,
@Tylae@phpc.social avatar

@Crell let's be controversial: you shouldn't use the phrasing "type hint" in the current version of PHP. 😛

Crell,
@Crell@phpc.social avatar

@Tylae Touché.

Can't rename the article now, though, because of how Hive works.

ian,
@ian@phpc.social avatar
ramsey,
@ramsey@phpc.social avatar

@Tylae @Crell You’ve piqued my interest. Why not?

Tylae,
@Tylae@phpc.social avatar

@ramsey @Crell we have a fully capable type system with runtime enforcement. The phrasing "type hint" is used when it's a "hint" but there's nothing in the runtime to enforce it.

Tylae,
@Tylae@phpc.social avatar

@ramsey @Crell give or take. I'm not 100% on whether I have the definition for type hints correct.

Crell,
@Crell@phpc.social avatar

@Tylae @ramsey It's a term that has no official definition, but your description is the standard operating definition most internals folks use.

ramsey,
@ramsey@phpc.social avatar

@Tylae @Crell Ha! I never thought about the inaccuracy of the word “hint.” 😁

ian,
@ian@phpc.social avatar

@ramsey @Tylae @Crell you could say that calling types hints is type erasure

I'll C myself out.

gmazzap,
@gmazzap@phpc.social avatar

@ramsey @Tylae @Crell The PHP docs, AFAIK, never calls them "type hints" but always "type declarations".

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