Sand Fox
-
Pseudolocale Lib for PHP
I haven't found a good standalone pseudolocalization library for PHP so I wrote my own.
https://sandfox.dev/php/pseudolocale.html
Or if you're using Symfony Components or you don't mind using huge libraries for simple tasks, there is one good alternative:
PseudoLocalizationTranslator
in the Symfony Translation Component since version 5.2. -
Trash Directory for Partition
If you have a separate user writable drive mounted, you may have encountered the same problem I had. If your DE cannot create
.Trash-$uid
, most DEs will not delete files to the trash at all and KDE will copy deleted files to your home partition. I find both behaviors frustrating.The solution is rather simple: look at the spec and create the trash directory manually.
# for example, your drive is mounted to /media/external # go to the drive root cd /media/external # create root owned .Trash sudo mkdir .Trash # make it world writable with a sticky bit sudo chmod 1777 .Trash
Note
Sticky bit is used for retaining control over your files in a publicly writable directory. Only the owner of the file can delete or rename it even if other users have write permission in the parent directory. This is a typical permission for
/tmp
. Read moreNow delete some file from that partition and check that is lands to
.Trash/$uid/files
. Your trash directory now works properly. -
PHP 8.0 Comparison Change
Another new thing in PHP 8.0 will be slightly less madness in non strict value comparison.
-
OOP in PHP 4 and 8
Deprecation of class name constructors means that you no longer can write OOP code that works both in PHP 4 and PHP 8 without some hackery. This works however:
<?php class WorksIn4And8 { var $int; // Regular method in PHP 4 // Constructor in 5-8 function __construct($int) { error_log('__construct()'); $this->int = $int; } // Constructor in PHP 4 // Constructor overridden by __construct in 5-7 // Regular method in PHP 8 function WorksIn4And8($int) { error_log('WorksIn4And8()'); $this->__construct($int); } function getInt() { return $this->int; } } $obj = new WorksIn4And8(48); var_dump($obj->getInt());
-
PHP 8.0 Syntax Showcase
Since RC1 is released today, I decided to make a small demonstration of PHP 8.0 syntax features.
<?php #[FuncAttribute] function func(SplHeap|ArrayObject|null $object, mixed $value = null): ArrayAccess|false { return match ($object?->count()) { 0, null => throw new RuntimeException(), default => $object, }; } try { func(object: new ArrayObject()); } catch (RuntimeException) { // ignore }
-
OTP Links
Have you ever seen an one time password link in a regular
<a>
tag?Here is an example TOTP link from Google Authenticator repo:
otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example
The most familiar form for them is QR codes:
Which is a problem if you're alterady on your mobile device and you can't scan it. For this case there is usually a text like "Please manually add the key
JBSW Y3DP EHPK 3PXP
to your Authenticator app". But what about the link itself? Well, just try it on your phone: click me.I'm really shocked that it works perfectly and that I have never seen this simple and very web style solution in action.
-
Method Calls with Arbitrary Names
-
Kernel#send Should Be Removed
Opinion:
Kernel#send
should be deprecated and removed from future rubies.send
always felt weird when I was an active ruby developer but I have never seen any strong criticisms on it. It's either an attack on all family of send-like calls or a fierce defence that "usingsend
is not a bad practice". Only some style guides argue againstsend
because it may overlap with existing methods. This post was written after reading one of defences. -
I released the first PHP 8 library ever
At least among the libraries listed on the Packagist. On this Tuesday sandfoxme/bencode was updated to 2.0 that requires PHP 8 as a minimum. While it was meant mostly as an experiment and a joke, it allowed me to try some new features like
Stringable
interface and remove some old compatibility handling thanks tombstring.func_overload
being finally removed. -
sabre/xml
An awesome discovery of today was made in an article titled An XML library for PHP you may not hate. As an unexpected twist I really didn't hate it, in fact it helped me to solve a problem that I had. It is called sabre/xml and it's a part of the sabre/dav project.