dseguy, French
@dseguy@phpc.social avatar

What is a
function which has a return type, yet doesn't return anything?


heiglandreas,
@heiglandreas@phpc.social avatar

@dseguy And even : X|nulldoesn't help!

Only void works as "return type"...

dseguy,
@dseguy@phpc.social avatar

@heiglandreas So, try replacing X with another type, and may be add more code before return, to make the error disappear.

heiglandreas, (edited )
@heiglandreas@phpc.social avatar

@dseguy Works fine when using Generator instead of X 😁

function foo(): Generator
{
yield 1;
return;
}

Just aliasing Generator to X doesn'T work as class_alias only works with user-defined classes 😕

dseguy,
@dseguy@phpc.social avatar

@heiglandreas Good old Generator... You found it.

heiglandreas,
@heiglandreas@phpc.social avatar

@dseguy Though I'd argue that yield is ... returnPlus? advancedReturn? 😁

But it definitely doesn't return the type that is stated 😁

dseguy,
@dseguy@phpc.social avatar

@heiglandreas yield is not typed in .

That's one of the places where type system is lacking.

ramsey,
@ramsey@phpc.social avatar

@dseguy @heiglandreas It yields (returns) a type of Generator, right?

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