What’s New in PHP 7.4 (Features, Deprecations, Speed)

What’s New in PHP 7.4 (Features, Deprecations, Speed)

PHP 7.4 will be released on November 28, 2019. Its features include:

  • Arrow functions for cleaner one-liner functions
  • Preloading to improve performance
  • Typed properties in classes
  • Improved type variance
  • The null coalescing assignment operator as a shorthand
  • FFI for better extension development in PHP
  • Underscores can be used to format numeric values
  • Spread operator in arrays
  • And more, you can read about it here

New Features?

Arrow functions 

Arrow functions, also called “short closures”, allow for less verbose one-liner functions.

While you’d previously write this:

array_map(function (User $user) { 
    return $user->id; 
}, $users)

You can now write this:

array_map(fn (User $user) => $user->id, $users)

There are a few notes about arrow functions:

  • They can always access the parent scope, there’s no need for the use keyword.
  • $this is available just like normal closures.
  • Arrow functions may only contain one line, which is also the return statement.

Typed properties

Class variables can be type hinted:

class A
{
    public string $name;
    
    public ?Foo $foo;
}

Improved type variance

I also wrote about PHP’s type system in the past, so it’s good to see some improvements are actually arriving in PHP’s core.

Type variance is another topic worth its own blog post, but in short: you’ll be able use covariant return types –

class ParentType {}
class ChildType extends ParentType {}

class A
{
    public function covariantReturnTypes(): ParentType
    { /* … */ }
}

class B extends A
{
    public function covariantReturnTypes(): ChildType
    { /* … */ }
}

– and contravariant arguments.

class A
{
    public function contraVariantArguments(ChildType $type)
    { /* … */ }
}

class B extends A
{
    public function contraVariantArguments(ParentType $type)
    { /* … */ }
}

Null coalescing assignment operator

Next is the null coalescing assignment operator, a shorthand for null coalescing operations. Instead of doing this:

$data['date'] = $data['date'] ?? new DateTime();

You can do this:

$data['date'] ??= new DateTime();

Array spread operator

Next up, it’s now possible to use the spread operator in arrays:

$arrayA = [1, 2, 3];
\
$arrayB = [4, 5];

$result = [0, ...$arrayA, ...$arrayB, 6 ,7];

// [0, 1, 2, 3, 4, 5, 6, 7]

Note that this only works with arrays with numerical keys.

Numeric Literal Separator

PHP 7.4 allows for underscores to be used to visually separate numeric values. It looks like this:

$unformattedNumber = 107925284.88;

$formattedNumber = 107_925_284.88;

Foreign function interface

Preloading

Custom object serialization

Reflection for references

Weak references

mb_str_split added

Password Hashing Registry

Left-associative ternary operator deprecation

Exceptions allowed in __toString

Concatenation precedence

PEAR not enabled by default 

Should You Upgrade to the iPhone 11 Pro?

  • The new iPhone 11 Pro and iPhone 11 Pro Max feature three cameras for more dynamic photos and video options.
  • With a new chip, the iPhone’s machine learning capabilities have gotten six times better, opening the door for loads of new applications.
  • You can begin pre-ordering the phone on Friday. The phones will start shipping on September 20

Three camera lenses on the back of the phone, among other improvements, make the iPhone 11 Pro and iPhone 11 Pro Max stand out from other models. Is that enough to justify their $999 and $1,099 price tags, respectively? That depends on your current iPhone.

The most significant change to the phones is definitely the camera array, which allows users to take better photos in low lighting, zoom in and out with ease, and even take professional-grade video that takes advantage of all the unique angles the iPhone can capture at once.

Video has also received huge improvements. You can now shoot in 4K at 24, 30, or 60 fps. Audio Zoom ensures that music or sounds align to the video, even when you get closer to the subject.

So if you’re a photographer, it’s definitely worth the upgrade, especially if you like to print out photos. And if you’re a gamer, this may also be the phone for you.

Boasting the fastest performing chip yet, the A13 Bionic, the new iPhone line has dramatically increased machine learning capabilities with a new third-generation neural engine. The phone can handle one trillion operations per second, so don’t worry about any more annoying crashes.

Both the iPhone 11 Pro and iPhone 11 Pro Max come in 64, 256, and 512 GB models. The iPhone 11 Pro weighs 6.63 ounces with a 5.8-inch screen, while the Max comes in at 7.97 ounces with a 6.5-inch screen.

If you already have the iPhone X, you probably don’t need to rush out to upgrade just yet. But if you need a lightning-fast, powerful phone for photos, gaming, and other daily media use, the iPhone 11 Pro and iPhone 11 Pro Max could change the game.


How to Reduce Time to First Byte and Load Your Site Faster

What is TTFB?

TTFB refers to the amount of time it takes a browser to create a connection to the server and start downloading the contents of a web page.

Google defines TTFB as a period of “waiting”

To put it simply, TTFB is the amount of time from the moment you navigate to a web page to the moment it starts rendering.

WHAT CAUSES A SLOW TTFB?

When it comes to WordPress sites, there are several different factors that can affect TTFB:

Network latency
High web traffic
Server configuration and performance
Dynamic content
DNS response time

There isn’t much you can do to solve high web traffic or network issues. But there are ways you can address server configuration, dynamic content, and DNS response times, which we’ll explore below.

How to improve TTFB?

1. Use a Fast Web Host

2. Keep site, Plugins and Themes Updated

3. Reduce Queries

4. Use Caching

5. Use a CDN

6. Use a Premium DNS Service

There are loads of other advanced techniques you could implement on your site to improve your TTFB, such as Disk IO, TLS overhead, reducing autoloaded data, and more.


How to make your website load lightning fast with WebP images

What is WebP?

WebP is a modern image format that provides superior lossless and lossy compression for images on the web. Using WebP, webmasters and web developers can create smaller, richer images that make the web faster.

Google claims that a WebP lossless image is 26% smaller than its PNG equivalent, and that a WebP lossy image is 25–34% smaller than its JPG equivalent (as of Feb. 2019).

Let’s take WebP images for a test. When I ran my JPG image through the WebP converter, I got the following results:

  • JPG image (already compressed): 279 KB
  • WebP at 100% lossless: 451 KB (yes, this is higher — more on why below!)
  • WebP at 80% lossy: 156 KB (56% of the original size)

How WebP Works

Lossy WebP compression uses predictive coding to encode an image, the same method used by the VP8 video codec to compress keyframes in videos. Predictive coding uses the values in neighboring blocks of pixels to predict the values in a block, and then encodes only the difference. Lossless WebP compression uses already seen image fragments in order to exactly reconstruct new pixels. It can also use a local palette if no interesting match is found.

Using WebP — with JPEG/PNG As a Fallback

Just because Apple doesn’t support WebP, doesn’t mean you shouldn’t use the format. It’s possible to deliver WebP files to visitors who use supported browsers while displaying JPEGs and PNGs as a fallback to Safari users. This way, rather than deliver WebP to all users and risk Safari users seeing broken images, you can ensure all visitors to your site see your images — while users with supported browsers get a faster experience.


Best Actor Websites Built with WordPress

Leonardo Dicaprio

Leonardo Dicaprio’s website easily stands out amongst other actor websites. A full-screen automatic slider displays stunning images of Dicaprio. The homepage is then divided into sections, with videos from his most recent film, powerful quotes from a selection of other films he has starred in, and recent blog articles.

Beyonce

Beyonce’s WordPress website uses a bold white and black color scheme, which makes a lasting impression. The homepage is made up of full-screen shots of Beyonce in a variety of outfits. Clicking on individual images displays social media buttons, encouraging social shares.

Sylvester Stallone

Sylvester Stallone’s website is classic, stylish, and very well organized. This WordPress site uses a white background with black text. A large full width featured image of Sylvester dominates the homepage. And a plain menu runs along the top of the page, so visitors can easily see what content is available to access.

Russell Brand

Actor and comedian Russell Brand has really embraced his website’s design. The result is a WordPress site that reflects his loud and chaotic personality. A parallel effect, with moving content and a bright, spotty background helps immediately grab visitor’s attention. Content is written in the first person, which helps his audience connect and engage with him.

What is difference between CNAME and A Record?

The A and CNAME records are the two common ways to map a host name (“name”) to one or more IP addresses. There are important differences between these two records.

The A record points a name to a specific IP. If you want blog.xyz.com to point to the server 185.31.17.134 you’ll configure:

blog.xyz.com.     A        185.31.17.134

The CNAME record points a name to another name instead of to an IP. The CNAME source represents an alias for the target name and inherits its entire resolution chain.

An A record points a name to an IP. A CNAME record can point a name to another CNAME or to an A record.

Important rules:

  • The ACNAME, and ALIAS records cause a name to resolve to an IP. Conversely, the URLrecord redirects the name to a destination. The URL record is a simple and effective way to apply a redirect for one name to another name, for example redirecting www.XYZ.com to XYZ.com.
  • The A name must resolve to an IP. The CNAME and ALIAS records must point to a name.

You should never use a CNAME record for your root domain name (e.g. XYZ.com).

WordPress + Google Cloud

How to set up WordPress in Google Cloud for Free?

Strong Customer Authentication: SCA and Store owners

Attention Store Owners

Update your payment gateways before September 14, 2019

From September 14, 2019 new rules to cut card fraud are fast approaching. But what does it mean for online shopping?

The system is designed to protect consumers, retailers and card issuers from fraud, but genuine transactions were inevitable collateral damage. Not every retailer used the additional layer of security but new regulations coming in the next few months will require most online payments to be subject to stronger authentication.

Part of the Revised Payment Services Directive (PSD2) published in 2018, Strong Customer Authentication (SCA) is intended to make payments more secure, requiring online sellers to implement more stringent methods of ensuring the payments they are taking are genuine. The rules, which come into effect on September 14th, mean customers will have to approve online payments through a second level of authorisation where the cardholder’s bank and the business accepting the transaction are located in the European Economic Area.

Some online retailers use 3DSecure such as Verified by Visa and Mastercard Identity Check. But many more businesses will be required to use SCA for online payments. That requires a degree of preparation from the retailer, payment processors and banks. The updated version of 3DSecure, which is expected to be adopted by European banks before the SCA D-Day in September, promises to be less frustrating for consumers to use, which is good news for anyone who has struggled with the systems in the past. Not only does it ditch the password-only option, allowing customers to use biometrics and tokens to approve the payments, it is also designed to be mobile friendly.

Retailers will have to ensure their payments systems are upgraded prior to the deadline for SCA, integrating 3DSecure to their checkout process. How simple that is will depend on each business’s set up. Much of the changes brought about under SCA, including navigating the exemptions, can be handled by payment processors such as Stripe, PayPal or WorldPay.