dseguy, 2 months ago French What is a #PHP function which has a return type, yet doesn't return anything? #phptip #phptrick
What is a #PHP function which has a return type, yet doesn't return anything?
#phptip #phptrick
heiglandreas, 2 months ago French @dseguy And even : X|nulldoesn't help! Only void works as "return type"...
@dseguy And even : X|nulldoesn't help!
: X|null
Only void works as "return type"...
dseguy, 2 months ago French @heiglandreas So, try replacing X with another type, and may be add more code before return, to make the error disappear.
@heiglandreas So, try replacing X with another type, and may be add more code before return, to make the error disappear.
heiglandreas, 2 months ago (edited 2 months ago) French @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 Works fine when using Generator instead of X 😁
Generator
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, 2 months ago French @heiglandreas Good old Generator... You found it.
@heiglandreas Good old Generator... You found it.
heiglandreas, 2 months ago French @dseguy Though I'd argue that yield is ... returnPlus? advancedReturn? 😁 But it definitely doesn't return the type that is stated 😁
@dseguy Though I'd argue that yield is ... returnPlus? advancedReturn? 😁
yield
But it definitely doesn't return the type that is stated 😁
dseguy, 2 months ago French @heiglandreas yield is not typed in #PHP. That's one of the places where type system is lacking.
@heiglandreas yield is not typed in #PHP.
That's one of the places where type system is lacking.
ramsey, 2 months ago @dseguy @heiglandreas It yields (returns) a type of Generator, right?
@dseguy @heiglandreas It yields (returns) a type of Generator, right?
Add comment