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

Here is the PHPuzzle of the day. Which of the following line is wrong in PHP 8.3 ?

Assume that all needed definitions are available for this to run.

MaxKoder,

@dseguy
Think is A::{A}; cause others seems ok, and I dont understand this.

dseguy,
@dseguy@phpc.social avatar

@MaxKoder This is new in PHP 8.3 : dynamic class constant.
The weird part here is that the constant name is evaluated: so we can use a global constant name there.
In the end, this is not a call to A::A, but a call to A::value_of_constant('A').
It's easier to recognize with A::{$A} where $A is a constant.

MaxKoder,

@dseguy
Thanks for your reply, it will become hard to understand ^^

Daddaniele,

@dseguy an extra }

dseguy,
@dseguy@phpc.social avatar

@Daddaniele I fixed that one in the picture.
Now, where is the problem?

velkuns,
@velkuns@phpc.social avatar

@dseguy the last one has one extra }
But probably is a typo.

Otherwise, I don't know why it should be broken.

dseguy,
@dseguy@phpc.social avatar

@velkuns Yep, I fixed it.
So, where is the error?

velkuns,
@velkuns@phpc.social avatar

@dseguy is it $A{A} part that causes the error ? It is the only thing that differs from others cases.

dseguy,
@dseguy@phpc.social avatar

@velkuns Yes, that's it. curly braces are not allowed anymore to access elements at position x in a string or array, since PHP 8.0.

The rest are variations between dynamic class constants and dynamic property, with global constants for a bit of weirdness.

velkuns,
@velkuns@phpc.social avatar

@dseguy ah, yes, of course. But I didn't know this syntax works with letters between { }

dseguy,
@dseguy@phpc.social avatar

@velkuns another good reason to avoid this syntax.

admin,

@dseguy the last line ?>

dseguy,
@dseguy@phpc.social avatar

@admin Not bad. Any reason?

admin,

@dseguy
if have no clue
?>

dseguy,
@dseguy@phpc.social avatar

@admin It is valid to leave the (last) closing tag out. Not the problem here.

admin,

@dseguy is it the opening tag <?
(still have no clue)

dseguy,
@dseguy@phpc.social avatar

@admin
I'm giving you more time to find it.
The road is the destination!

admin,

@dseguy
now i will find it

admin,

@dseguy
Is this a good start?:

class A {
const string A = 'A';
}

dseguy,
@dseguy@phpc.social avatar

@admin It is.

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