e3betht,

Interesting chat at #phptek (@phptek) today.

My stance: Uninitialized variables and array keys are fine. Back-end security issues with setting them should be fixed in core, not worked around by banning them.

Please, convince me that uninitialized variables are wrong. I WANT TO BELIEVE!

And no, the following reasons do not convince me:

  1. It's Best Practice
  2. That's how other languages do it
  3. It's messy, ugly, or any other subjective term
  4. Real programmers should do things the right way
Crell,
@Crell@phpc.social avatar

@e3betht @phptek Default values should be provided in a single location. Undefined values means extra error handling for every potential read. Forcing a variable to be defined with a reasonable default simplifies all code that may read that variable.

e3betht,

@Crell @phptek Are you saying that you can trust a value if it has been previously defined? I could agree with that if it is defined in the same script and you are absolutely confident that line of code will be run, but otherwise, if you are truly being careful, I'm not sure you can trust it. Especially if it comes from a session, a library, or any other external source.

Crell,
@Crell@phpc.social avatar

@e3betht @phptek It's only relevant within the scope of one function/method. Within that, you should be able to control that all variables are defined and initialized.

The exception is object or array arguments. Which is why you should not pass arrays as data structures, and use fully typed objects that have constructors that make sure everything is initialized.

Then you can be certain a value is defined and has a legal value.

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