@velkuns@phpc.social avatar

velkuns

@velkuns@phpc.social

author of eureka-framework (with PSR-7) and some other components, like ORM, validator...
Also author of MySQL Queue system (for small queue < 100k): php-mqdb

working with PHP since more than 20 years

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

Crell, to php
@Crell@phpc.social avatar

Please, web app developers, consider how your users will upgrade. If your upgrade process is "remove the old one, unzip the new one", then it's not an upgrade process. It's an encouragement to never upgrade.

#PHP #Laravel #Programming

velkuns,
@velkuns@phpc.social avatar

@Crell @acelaya I created a deployer component.

I can integrate it in my app to deploy it in production.
I need to have a git repo on the server (mainly for private repo). And it configurable with y'all config.

But with a cli command, the component will:

  • creates an export of given tag
  • extracts it in some place
  • runs composer install
  • can run some other commands
  • copies secret files into app dir
  • create a symlink (for apache)

In case of problem, I redo a symlink on previous version

thomastospace, to php
@thomastospace@phpc.social avatar

I need some #PHP feedback on a test implementation of jwt token auth:

JWT tokens are valid forever, however we would like to invalidate all tokens when a user changes their password.

We've solved this by saving a random value at the user, and storing this in the token. Whenever the token is used, we check if this is the same. When a password gets changed, we also change this value, which then makes all old tokens invalid because they don't contain this value.

How does this sound to you?

velkuns,
@velkuns@phpc.social avatar

@thomastospace on my side, I store an hash of N last token generated for a user (because they may use many browser / pc.

To validate auth, I check if JWT is valid and if hash is stored.

So when they change the password, I clear the list of hash, then all the existing JWT are considered as unknown.

And can also be used to force "deconnection" from all devices (by clearing the stored hash list).

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

The #PHP code below produces a float, although it seems to produce an integer.

This is due to (int) having higher precedence than multiplication: it is applied to $c, without effect.

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

#phptip #phptrick

velkuns,
@velkuns@phpc.social avatar

@dseguy same for ternary operator. That's why explicit things like ( ) is recommended to avoid problems 😅

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

How to clean after oneself in #PHP ?

There are three methods to ensure that this little cleanup code is always executed, no matter what : register_shutdown_function(), function __destruct() and try-finally.

#phptip #phptrick

https://www.exakat.io/en/how-to-clean-after-oneself-in-php/

velkuns,
@velkuns@phpc.social avatar

@dseguy cool article 👍

Just a typo in second example: the first method should be __construct(), I guess 🙂

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

Here is a very optional #PHP command : try-catch-finally

The finally clause in a try-catch-finally is optional: it can be omitted and often is.

The catch clauses in a try-catch-finally are also optional: they can be omitted.

When the catch and finally clauses are all omitted, the try clause can also be omitted. Safely.

#phptip #phptrick

https://php-tips.readthedocs.io/en/latest/tips/try-catch-finally.html

velkuns,
@velkuns@phpc.social avatar

@dseguy try/finally could be useful in some specifics cases 😁

velkuns,
@velkuns@phpc.social avatar
velkuns,
@velkuns@phpc.social avatar

@dseguy @Exakat one use case in mind is when I open a resource (file for example).

I need to close it in any case. But not necessary to catch any exception. So just try/finally can help to avoid duplicate code to close the resource.

velkuns,
@velkuns@phpc.social avatar

@dseguy @Exakat yes.

Lots of use cases, finally 😁

Thanks to PHP to permit this kind of thing ❤️

Girgias, (edited ) to php
@Girgias@phpc.social avatar

Quick question for the masses:

When you use bitwise operators in , with what input types do you use them?

velkuns,
@velkuns@phpc.social avatar

@Girgias I discovered recently we can use it with string and bypass the int 64 limitation for bitwise operators. So can be useful when 63 values is not enough.

But generally, I use it with int or int binary version, it's depend

heiglandreas, (edited ) to random
@heiglandreas@phpc.social avatar

TIL that

$a = set_error_handler('my_error_handler');
set_error_handler($a);

is something different than

set_error_handler('my_error_handler');
restore_error_handler();

🤯

#php

Edit: Fixed typos

velkuns,
@velkuns@phpc.social avatar

@heiglandreas @bhhaskin the first part is back to previous handler (that may not be the initial one, because it had may be redefined preciously).

The second one just reset the handler to the original default state.

Effectively, it makes sense when we take time to think about it 👍

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

#PHP is better than me : I thought I found a way to create properties in an interface, by declaring promoted properties in a constructor.

Someone coding the PHP engine was smarter than me : it feels so good! (BTW, who would that be?)

It's also going to save me some sanity, as I don't have to upgrade my Static Analysis Engine.

#phptip #phptrick

velkuns,
@velkuns@phpc.social avatar

@dseguy One or two month ago, I thought the propertiez in interfaces will be a non-sense.

But after trying to use public properties in some classes implementing an interface, I'm not so sure about my previous thoughts 😅

I probably need to read again the RFC about it, to see it could be finally a great new feature for PHP :)

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

I've completed Part One of "Pulse Propagation" - Day 20 - Advent of Code 2023 https://adventofcode.com/2023/day/20

done with

Code here: https://github.com/velkuns/adventofcode-2023/blob/main/src/Day/PuzzleDay20.php
+
Some objects for clean code: https://github.com/velkuns/adventofcode-2023/tree/main/src/Day20

Part 1 was easy with clear logic in mind, no bug.
Part 2 ... still running (it tooks ~ 55s for 1million times), so I don't know when it will finish, but probably in long time 😅
Maybe the response tomorrow morning 😄
But it was fun to code !

velkuns,
@velkuns@phpc.social avatar

@jeff same for me. I do some minor OOP before, but yeah, this one is more logical for OOP.

That's why a made a directory for day20 classes 😅

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

When using the #PHP null safe operator ?-> , note that the checks are still necessary, and that it also impacts the types of the methods involved.

It is a significant change with -> which needs pre-checks.

https://www.exakat.io/en/null-safe-operator-in-practice/

velkuns,
@velkuns@phpc.social avatar

@dseguy @amarok another way to use it:

$result = getInstance('what')?->getInt() ?? 0;

Can also throw an exception depending the context:

$result = getInstance('what')?->getObject() ?? throw new \Exception();

But it is better to use to get property value if defined rather than on a method.
But we always have an exception for that usage 😁

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

I've completed Part One of "Aplenty" - Day 19 - Advent of Code 2023 https://adventofcode.com/2023/day/19

Done in

Code: https://github.com/velkuns/adventofcode-2023/blob/main/src/Day/PuzzleDay19.php

Just only the part 1 today. I don't really like this kind of part 2 with optimised range calculation, so just skip it and have some rest for remaining time :D

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

I just completed "Lavaduct Lagoon" - Day 18 - Advent of Code 2023 #AdventOfCode https://adventofcode.com/2023/day/18

done with #php

Part 1: hard to try appropriate formula & fix the code, part 2 will provide the exact result without any fix or change.

Code here: https://github.com/velkuns/adventofcode-2023/blob/main/src/Day/PuzzleDay18.php
Also re-use an enum from Day 10: https://github.com/velkuns/adventofcode-2023/blob/main/src/Enum/PathDirection.php

jeff, (edited ) to php
@jeff@phpc.social avatar

I just completed "Lens Library" - Day 15 - Advent of Code 2023

This was really close to three one-liners. A nice break from the past few days.

This one really benefitted from being an array-based language w/ ordered hash tables by default.

I used array_keys(filter) to treat keys as associative and indexed at the same time.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/15-lens-library/solution.php?ts=4

velkuns,
@velkuns@phpc.social avatar

@jeff I don't understand the value of box in example for part 2, because it doesn't match the hash value for each sequence of the example from part 1 🤔

velkuns,
@velkuns@phpc.social avatar

@jeff ok, just need to read five times to really understand that I need to hash only the label 😅

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

question : what do you use PHP_INT_MAX for ?

It is the largest integer possible, though not the largest number. So, what are its applications?

Share your experience (I'll start)

velkuns,
@velkuns@phpc.social avatar

@derickr @dseguy same for the part 2.

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

I just completed "Parabolic Reflector Dish" - Day 14 - Advent of Code 2023 #AdventOfCode https://adventofcode.com/2023/day/14

Done with #php

Not so complicated today. Once again, my Matrix class was very helpful.

And final try was false due to miss read the number of cycle to reach (1 million instead of 1 billion 😅)
Fun fact: brute force will take ~100 year to achieve with my current code 😆

Code: https://github.com/velkuns/adventofcode-2023/blob/main/src/Day/PuzzleDay14.php
+
https://github.com/velkuns/adventofcode-2023/blob/main/src/Service/Platform.php (extended Matrix class)

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

I just completed "Cosmic Expansion" - Day 11 - Advent of Code 2023 #AdventOfCode https://adventofcode.com/2023/day/11

Done with #php

Code here: https://github.com/velkuns/adventofcode-2023/blob/main/src/Day/PuzzleDay11.php
+
https://github.com/velkuns/adventofcode-2023/blob/main/src/Service/Universe.php (extended Matrix)

Quite simple today, but a little bit challenging on part 2

The time to process for part 1 can be around 180ms (2 times less) by using real expanse of the matrix

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

I just completed "Pipe Maze" - Day 10 - Advent of Code 2023 #AdventOfCode https://adventofcode.com/2023/day/10

Done with #php

Code: https://github.com/velkuns/adventofcode-2023/blob/main/src/Day/PuzzleDay10.php
+
https://github.com/velkuns/adventofcode-2023/blob/main/src/Service/Maze.php
https://github.com/velkunfs/adventofcode-2023/blob/main/src/Enum/PathDirection.php

Naming can be probably improved, but seem ok.
I tried to factorise and clean up the code.

Proud of my solution (even if it is maybe not the best one), with time under the second for both part !

And no error in algorithm for the part 2 <3
Just take so much time to refactor and rename the code, haha

jeff, (edited ) to php
@jeff@phpc.social avatar

I've completed "Mirage Maintenance" - Day 9 - Advent of Code 2023 #AdventOfCode #PHP

This was a quick one.

https://github.com/jstanden/advent-of-code-php/blob/main/2023/09-mirage-maint/solution.php?ts=4

velkuns,
@velkuns@phpc.social avatar

@jeff we have very different code today.

Too many array in array for me in your code 😅
But is an interesting approach without recursion

velkuns,
@velkuns@phpc.social avatar

@jeff it is not really dirty. Maybe missing some comments to ease the understanding 😁

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

I just completed "Haunted Wasteland" - Day 8 - Advent of Code 2023 #AdventOfCode https://adventofcode.com/2023/day/8

Done with #php

Code here: https://github.com/velkuns/adventofcode-2023/blob/main/src/Day/PuzzleDay8.php

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