Sand Fox (old posts, page 4)
-
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.
-
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
A discovery of the day. Many people know that you can define and read an object property with an arbitrary name:
-
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.
-
Is NEON a Better YAML?
Short answer: NO. If you know what I mean.
-
What's Wrong with StrictYAML
While I'm still delaying my position on TOML vs YAML holy war let's look at the StrictYAML.
StrictYAML is a type-safe YAML parser that parses and validates a restricted subset of the YAML specification.
Seems great but let's look at the removed features list, Implicit Typing to be precise: