dseguy, French
@dseguy@phpc.social avatar

Useless tip of the day:

Null and booleans accept the array syntax, but always return NULL (and a warning)

Illegal types for array keys lead to a Fatal Error.

But not with NULL and booleans.

https://php-tips.readthedocs.io/en/latest/tips/nullAsArray.html

dseguy,
@dseguy@phpc.social avatar

How come [][[]] is a lintable syntax is a still a mystery to me.

b_viguier,
@b_viguier@phpc.social avatar

@dseguy I guess [[]] is an edge case hard to exclude from the « generic » rule? Because something like this is valid and doesn’t produce any warning:

var_dump([][![]] ?? 'default');

🤷

dseguy,
@dseguy@phpc.social avatar

@b_viguier I am leaning toward 'it's not worth the effort'.

[][![]] is valid code (! cast the [] to boolean).

[][[]] Is not valid from the lint.

const A = []; [][A] ; is not valid but needs execution.

The border between the last two lines is very gray.

wyri,
@wyri@haxim.us avatar

@dseguy can [] be transformed into 0 some how?

dseguy,
@dseguy@phpc.social avatar

@wyri Which []? There are too many of them!

It is a fatal error, no type juggling. You need to force (cast) the type to make this to run.

array()[ array() ] is at least a bit more readable. 😂

wyri,
@wyri@haxim.us avatar

@dseguy The second array() in your last line 😅

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