dseguy, (edited ) French
@dseguy@phpc.social avatar

Quizz question :

Can you write a function that won't execute when you call it?

(Just change the comment // more code )

dusoft,
@dusoft@fosstodon.org avatar

@dseguy yeah, just use early return

dseguy,
@dseguy@phpc.social avatar

@dusoft It could work when short-circuiting code.

Her, the echo FUNCTION will still display something, unless the return is before the echo. The challenge is to put the code AFTER the echo.

edorian,
@edorian@phpc.social avatar

@dseguy Turning the function into a generator with a ' yield 1; ' or similar should do the trick.

Can't think of any other way to prevent the echo. Of course printing backspaces would work not "display anything" but that feels like cheating with semantics.

dseguy,
@dseguy@phpc.social avatar

@edorian yield or its cousin, yield from.

Deuchnord,
@Deuchnord@mamot.fr avatar

@dseguy I don’t understand what you mean: I’ve just put your code in 3v4l and it works as expected: the function displays “foo” and then we display “the end” 🤔

dseguy,
@dseguy@phpc.social avatar

@Deuchnord You need to replace the comment

"// more code "

and make the PHP function not execute, even if called.

I see that the double usage of 'call' is confusing in the initial message. Let me rephrase a bit.

Deuchnord,
@Deuchnord@mamot.fr avatar

@dseguy okay, now I get it!
Sounds weird, does PHP really allows that? oO

dseguy,
@dseguy@phpc.social avatar

@Deuchnord Well, I do run into crazy pieces of code all the time, and I share them 🤭

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