b_viguier, French
@b_viguier@phpc.social avatar

TIL: in , you can create a new instance (not a clone) of an object from an existing instance with the following syntax:

$a1 = new A();
$a2 = new $a1();

Very convenient with anonymous classes! Just a bit confusing if you expect $a1() to call the A::__invoke magic method (because it won’t)

sarah,
@sarah@phpc.social avatar

@b_viguier @theseer I would probably limit this only to anonymous classes just to keep the code clean. I wouldn’t have known what this did just by looking at it in context.

theseer,
@theseer@phpc.social avatar

@sarah me neither :-)

b_viguier,
@b_viguier@phpc.social avatar

@sarah @theseer I do agree! This syntax is maybe more explicit:

$a2 = new ($a1::class)();

thgs,
@thgs@phpc.social avatar

@b_viguier @sarah @theseer and if you remove the ::class but keep the parentheses one would expect __invoke to be called

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