@dseguy@phpc.social
@dseguy@phpc.social avatar

dseguy

@dseguy@phpc.social

Static code analysis maestro https://phpc.social/@Exakat #PHP expert elePHPant breeder

This profile is from a federated server and may be incomplete. Browse more on the original instance.

dseguy, to php French
@dseguy@phpc.social avatar

allows to use 'class' as a class name in a type. Same for interface, enum... and some others.

Hey! I'm also not too proud of myself, but it made me chuckle.

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

dseguy, to php French
@dseguy@phpc.social avatar

has a 'precision' directive that controls the number of decimals displayed by float values.

It default to 14, and peaks at 18, and gives up at 54. Use gmp for large numbers.

When changing it, don't forget to reset it to default, unless you like to puzzle people.

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

dseguy, to php French
@dseguy@phpc.social avatar

doesn't allow float as index in arrays.

It is possible to use them as such by casting them to string. Later, type juggling will allow adding to another float, seamlessly.

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

dseguy,
@dseguy@phpc.social avatar

@mitelg mea culpa, it was seamless in the case I was working on.

With a finite float, it works.

With calculated float, there are possible hidden decimals : https://3v4l.org/dJ0mP;

It will loose precision with the default 'precision' (the directive), but not with higher levels (due to truncation).

nixCraft, to random
@nixCraft@mastodon.social avatar

PHP was originally an abbreviation of Personal Home Page 🤔 did you know that?

dseguy,
@dseguy@phpc.social avatar

@nixCraft Indeed. It also means a lot of other things, funny or downright serious.

https://www.exakat.io/en/what-does-php-mean/

dseguy, to php French
@dseguy@phpc.social avatar

Thursday, April 11th is @010php day, hosted by @bitfactory.

This month's session is about advanced type usage. See the impact of types on the structure of your code, identify impossible methods and design the others!

Go! https://www.meetup.com/010php/events/299863925/

dseguy, to php French
@dseguy@phpc.social avatar

has (int) and (integer) cast operators, but only the int type.

'integer' type is presumed to be a class. It raises a warning, even if it exists.

"integer" will be interpreted as a class name. Did you mean "int"? Write "\integer" to suppress this warning

dseguy, to php French
@dseguy@phpc.social avatar

I finally found an occurrence of this beauty :

$this->$this

It still looks like a typo in the original code, but with the help of __toString, it works. Also, strict_types doesn't help here.

https://php-tips.readthedocs.io/en/latest/tips/this_this.html and more tips!

dseguy,
@dseguy@phpc.social avatar

@Crell I knew that trick for a while now, but I only found it in actual code yesterday.

One less to find in the wild, still waiting for a few of them to appear.

"If there is a mean, there is a will."

dseguy,
@dseguy@phpc.social avatar

@ocramius 'that was not a question' (tm)

dseguy,
@dseguy@phpc.social avatar

@NanoSector it took me a few years to find one in the wild. You can relax.

dseguy,
@dseguy@phpc.social avatar

@asgrim @ocramius This was not a question!

dseguy,
@dseguy@phpc.social avatar

@pollita Coming from you, I take it as a compliment. Thanks 😎

dseguy,
@dseguy@phpc.social avatar

@wez Touché.

dseguy,
@dseguy@phpc.social avatar

@edorian Always a pleasure.

As long as I don't find this in your code, of course. 😂

dseguy,
@dseguy@phpc.social avatar

@heiglandreas 😂 :elephpant:

dseguy, to php French
@dseguy@phpc.social avatar

A variadic argument collects all the unused named parameters, along with their key. That way, it is possible to handle them with their name inside the method.

On the other hand, array_merge (and some cousins) refuse them, and emits a Fatal error.

dseguy, to php French
@dseguy@phpc.social avatar
  1. it is possible to call a method 'as', because relaxed keywords methods

  2. it is possible to import a method from a trait, and alias it to itself.

It is possible to write 'as as as ' in and make sense.

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

dseguy,
@dseguy@phpc.social avatar

@gmazzap 😂 😂
I just love it when using actual syntax to spell out a human readable message.

dseguy,
@dseguy@phpc.social avatar

@alessandrolai 😮 Aliased constructor...!! I might have overlooked that one.

dseguy, to php French
@dseguy@phpc.social avatar

What is a
function which has a return type, yet doesn't return anything?


dseguy,
@dseguy@phpc.social avatar

@heiglandreas So, try replacing X with another type, and may be add more code before return, to make the error disappear.

dseguy,
@dseguy@phpc.social avatar

@heiglandreas Good old Generator... You found it.

dseguy,
@dseguy@phpc.social avatar

@heiglandreas yield is not typed in .

That's one of the places where type system is lacking.

caroga, to random Dutch
@caroga@phpc.social avatar

Hey @dseguy, might you be joining us at the ?

dseguy,
@dseguy@phpc.social avatar

@heiglandreas @caroga Traversable is at home, but does request a trip once in a while. He is usually features when I do the elePHPant keynote.

Now that conferences are back, we might try this again!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • tester
  • hgfsjryuu7
  • magazineikmin
  • Youngstown
  • thenastyranch
  • GTA5RPClips
  • rosin
  • slotface
  • InstantRegret
  • ngwrru68w68
  • PowerRangers
  • kavyap
  • tsrsr
  • DreamBathrooms
  • Leos
  • mdbf
  • tacticalgear
  • khanakhh
  • cisconetworking
  • everett
  • Durango
  • ethstaker
  • vwfavf
  • cubers
  • normalnudes
  • osvaldo12
  • modclub
  • anitta
  • All magazines